This is my Java class
import java.util.Scanner;
public class first {
public static void main(String args[]);
int right_number, user_input;
right_number = 6;
Scanner in = new Scanner(System.in);
System.out.println("Enter a number between 1 and 10");
user_input = input.nextInt();
if(user_input = right_number) {
System.out.println("That is the right number!");
}
else {
System.out.println("Aww, try again by typing java first into commad line.");
}
}
It keeps saying this:
Error reached end of file while parsing.
Can anyone help?
This is the first problem:
public static void main(String args[]);
You're not actually declaring a method body here. It should be:
public static void main(String[] args) {
// Method body goes here
}
You should only use a ;
at the end of a method declaration for abstract methods (including those which are implicitly abstract in an interface). If you haven't got to abstract methods yet, just ignore that for the moment - basically use braces to provide a method body.
(The String[] args
vs String args[]
isn't a problem as such, but this version is preferred as a matter of style... as would naming your class First
rather than first
... there are various other style issues here, but I'll leave it at that for now.)
The fact that your class "tries" to end directly after an else
statement should be a warning bell - an else
statement can only appear in a method or constructor, so there has to be a brace to close that method/constructor and then a brace to close the class declaration itself. Likewise, the indentation should warn you of that - assuming you're using an IDE to perform the indentation, any time you find yourself writing method body statements which are only one level of indentation further than the class declaration, that suggests you have a problem somewhere - look up the file to see where it starts.
See more on this question at Stackoverflow