This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Code Error

 
Trae Carrington
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just now getting into java with Head First Java trying to run the following code and get the error

DooBee.java:9: ';' expected
If(x==3) {
^

What is wrong?

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");
}
}
}
 
Joe Ess
Bartender
Posts: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch.
Java is case-sensitive. The word "if" is different from the word "If". "if" is used for flow control. "If" is undefined, and since it is followed by parenthesis, the compiler assumes you are referencing a method named "If" and complains because you haven't terminated the method call with a ";".
 
Trae Carrington
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help. Still new at it rather than just move on I always try to find out what causes an error so don't pick up a bad habit.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic