Reese Reese - 2 months ago 7
Java Question

If statements not working in Java

I am new to java and am writing a guessing game code and the else if statement is underlined the code is

if (guess == random) {
System.out.println("Correct the number is "+random);

} else if (guess < random);{
System.out.println("Lower");
} else if (guess > random);{
System.out.println("higher");
}

Answer

Remove the semicolon after the conditions

Like this:

if (guess == random) {
   System.out.println("Correct the number is "+random);
} else if (guess < random){
   System.out.println("Lower"); 
} else if (guess > random){
   System.out.println("higher");
}

Look here for more information