• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting error please see and help it...

 
Supriya Dle
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?
 
teja dharma
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");
}
}
}
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
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.
 
Campbell Ritchie
Sheriff
Posts: 48371
56
  • 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
Sheriff
Posts: 48371
56
  • 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.
 
mansi gupte
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
Sheriff
Posts: 48371
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic