Multiple choice technology programming languages

What is the output of the following program? public class example { public static void main(String args[]) { int x=0, y=2; do { x=++x; y--; } while(y>0); System.out.println(x); } }

  1. 0

  2. 1

  3. 2

  4. Compilation Error

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

The loop runs twice. In the first iteration, x becomes 1 (via ++x) and y becomes 1. In the second iteration, x becomes 2 and y becomes 0. The loop terminates, and 2 is printed.