1.

Solve : Error on 'else' in statement. Java.?

Answer»

Hello. I am trying to make a menu in java USING an 'else if' statement.

Code: [Select]if (Selection == 1)
{
Thing 1;
}
else if (Selection == 2)
{
Thing 2;
}
else if (Selection == 3)
{
Thing 3;
}
else if (Selection == 4)
{
Thing 4;
}
else if (Selection == 5);
{
Thing 5;
}
else
{

}

For some reason I am getting an error on the last 'else' in the statement. If I delete it then the program will do what ever is selected but it will then also do the 5th thing. If I add an 'if' to the end of the else it will still show an error just on the 'else'. Does anyone know why this is happening and how to fix it?

Thanks.Ye man, you got a semi-color ( ; ) after fifth else if statement brackets.

here: else if (Selection == 5); <-- REMOVE it.By the way I'm assuming you're using console to do the menu. What do you use to READ the keyboard input? When I started learning I jumped right into the JOptionPane.Quote from: ultimatum on January 25, 2010, 11:07:31 AM

a semi-color ( ; )

a semi-colon

Thank you so MUCH. For user input the only way I know of is to use a scanner which you IMPORT.


Discussion

No Comment Found