| Author |
Getting error please see and help it...
|
Supriya Dle
Greenhorn
Joined: Feb 12, 2009
Posts: 3
|
|
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
Joined: Feb 07, 2009
Posts: 51
|
|
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");
}
}
}
|
SCJP 5
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24040
|
|
|
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.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
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
Joined: Feb 12, 2009
Posts: 3
|
|
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
Joined: Oct 13, 2005
Posts: 32599
|
|
|
Are you writing "if" or "If"? Please use ctrl-C ctrl-V to quote code if possible.
|
 |
mansi gupte
Ranch Hand
Joined: Dec 30, 2008
Posts: 72
|
|
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
Joined: Feb 12, 2009
Posts: 3
|
|
Thanks...
I have learn new things from you guys...!!
I will keep in mind from next time...
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
You're welcome
|
 |
 |
|
|
subject: Getting error please see and help it...
|
|
|