I have an exam on monday on java programming and i'm still a bit confused about a certain question involving nested if statements, the question is:
What is the output of the following code:
int x= 9;
int y = 8;
int z = 7;
if ( x> 9 )
if ( y > 8)
System.out.println(" x > 9 and z>=7");
else if ( z>= 7 )
System.out.println(" x <=9 and z>= 7" );
else
System.out.println(" x <=9 and z , 7 ");
the answer turned out to be" none of the above ", but I'm confused since when you have a nested if statements like this, why wouldn't it output "x<= 9 and z>= 7" since the condition for z is true?
I get that the condition for 9 being greater than x isn't true, so it moves onto the next if statement, and y is not greater than 8, so wouldn't it jump to the ' else if statement ' and output that? Or would it skip everything past "y>8" since that condition isn't true? Just a bit confused.