I am preparing for the OCA 8 examination ...
There was a question in the enthuware test, what is the proper structure of the following code(like which if belongs to which else - without curly brackets)?
if //statement 1
| if //statement 2
| else //statement 3
else //statement 4
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error on token "else", delete this token
If you do not put curly braces, only the first statement after
if() is considered. In your case, the two
if statements are nested but the first else statement is for the parent if, the second else hence is without an if.