This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Getting error please see and help it...  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new user of java & I will doing my teaching with Kathy Sierra & Bert Bates book (Head First Java)...
Today I am solve one program but getting error code is Below mention:
// Code
public class DooBee {
public static void main (String[]args) {
int x = 1;
while ( x < 2 ) {
System.out.print("Doo");
System.out.print("Bee");
x = x + 1 ;
}
If (x == 2){
System.out.print("Do");
}
}
}


Need output like this "DooBeeDooBeeDo"

Can any body help me?
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class DooBee {


public static void main(String[] args)
{
int x = 1;
while ( x < 3 ) {
System.out.print("Doo");
System.out.print("Bee");
x = x + 1 ;
}
if (x== 3){
System.out.print("Do");
}
}
}
 
author and iconoclast
Sheriff
Posts: 24220
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or preferably x should start at 0, and otherwise the program should stay as you originally had it. You're going to have to get used to counting from 0 -- that's how it's traditionally done in Java and most other programming languages.
 
Marshal
Posts: 60081
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch
What happens if you miss out the if (x == 3) test? Does it make any difference to the output?
 
Supriya Dle
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Thanks...

When I am using below coding:

public class DooBee {
public static void main (String[]args)
{
int x = 1;
while ( x < 3 ) {
System.out.print("Doo");
System.out.print("Bee");
x = x + 1 ;
}
If (x == 3){
System.out.print("Do");
}
}
}

"Getting error "DooBee.java:10: ';' expected
If (x == 3){
1 error"

And when I miss "If (x == 3)" then the program run sucessfully.... thanks Really grate experince in this forum...


 
Campbell Ritchie
Marshal
Posts: 60081
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you writing "if" or "If"? Please use ctrl-C ctrl-V to quote code if possible.
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Supriya Dle wrote:Hi All,

Thanks...

When I am using below coding:

public class DooBee {
public static void main (String[]args)
{
int x = 1;
while ( x < 3 ) {
System.out.print("Doo");
System.out.print("Bee");
x = x + 1 ;
}
If (x == 3){
System.out.print("Do");
}
}
}

"Getting error "DooBee.java:10: ';' expected
If (x == 3){
1 error"

And when I miss "If (x == 3)" then the program run sucessfully.... thanks Really grate experince in this forum...




Hi,

The error is a syntax error, java's keywords are case sensitive use if and not IF or If and the program would run fine
 
Supriya Dle
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks...

I have learn new things from you guys...!!

I will keep in mind from next time...
 
Campbell Ritchie
Marshal
Posts: 60081
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!