It will print out 5
. It doesn’t even approach to the second if-else
, because doesn’t pass the first condition x!=5
and the else
statement is missing and it goes to the last line where you print the variable out. It’s the same as:
int x=5, y=5, z=5;
if (x!=5) {
if (y<=7) {
z=z+4;
} else {
z=z+2;
}
}
System.out.println(z);
That’s the reason why using both of brackets ()
and {}
correctly are more than recommended!
solved No curly braces if else statements?