Otherwise, your tag will belong to 2nd if , not 1st if, as the indentation shows.
if(cond1)
if(cond2)
else // this else belongs to 2nd if not 1st if.
matches with:
if(cond1) {
if(cond2) {
} else {
}
}
This is because the Java grammar says that else belongs to the nearest unsurpassed, if it can belong .
If you want to combine else with the first, if you need to use parentheses like:
if(cond1) {
if(cond2) {
}
} else {
}
source
share