Multiple choice technology programming languages

class Demo { public static void main(String[] args) { int x = 9; int y = 6; for(int z = 0; z < 6; z++, y--) { if(x > 2) x--; label: if(x > 5) { System.out.print(x + " "}; --x; continue label; } x--; } } } What is the result?

  1. 8

  2. 8 7

  3. 8 7 6

  4. Compilation fails.

  5. An exception is thrown at runtime.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The code fails to compile for multiple reasons. First, there is a syntax error in the print statement, which ends with a closing brace instead of a parenthesis. Second, the continue statement attempts to target an if statement label instead of a loop, which is illegal in Java.