aspose file tools*
The moose likes Beginning Java and the fly likes Java Code Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Code Error" Watch "Java Code Error" New topic
Author

Java Code Error

Trae Carrington
Greenhorn

Joined: Feb 01, 2008
Posts: 2
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

Joined: Oct 29, 2001
Posts: 8866
    
    8

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 ";".


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Trae Carrington
Greenhorn

Joined: Feb 01, 2008
Posts: 2
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Code Error