What is the output of the following application?
public class MyClass { public static void main(String[] info) { int myField = 15; if(myField >= 15 && myField < 37) { System.out.print("Not enough"); } if(myField==37) { System.out.print("Just right"); } else { System.out.print("Too many"); } //ww w . j a va 2 s.c om } }
D.
The second if-then statement is not connected to the first if-then statement, as there is no else joining them.
When this code executes, the first if-then statement outputs Not enough since myField is >= 15 and < 37.
The second if-then statement is then evaluated.
Since myField is not 37, the expression Too many is outputted.
Since two statements are outputted, Option D, none of the above, is the correct answer.