I am a beginner at Java and this code example came up in class:
int horsepower = 15;
if(horsepower > 15)
if(horsepower <= 20)
System.out.println("There is a lot of horsepower");
else
System.out.println("The car super fast");
the output is nothing but I can't understand why.
I have 2 questions I would like to clarify:
- why did the code under the else statement not get executed?
- I understand that without the brackets { }, the if condition can only execute the next statement. In this case, if horsepower variable is 17 instead, will "There is a lot of horsepower." be printed ? I am unsure if the System.out.println("There is a lot of horsepower"); still qualifies as being part of the next statement of the first if condition.
Please advise. Thanks!
else
"belongs to" the 2ndif
.) $\endgroup$