Java OCA OCP Practice Question 1107

Question

What does the following code output?

int v = 0; 
while (v > 0) 
   System.out.println(v++); 
  • A. 0
  • B. The code does not compile.
  • C. The loops completes with no output.
  • D. This is an infinite loop.


C.

Note

A while loop checks the boolean condition before entering the loop.

In this code, that condition is false, so the loop body is never run.

No output is produced, and Option C is correct.




PreviousNext

Related