Win a copy of Design for the Mind this week in the Design 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
Pie
Posts: 9264
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