Multiple choice technology programming languages

What gets printed when the following code is compiled and run. Select the one correct answer. public class test { public static void main(String args[]) { int i = 1; do { i--; } while (i > 2); System.out.println(i); } }

  1. 0

  2. 1

  3. 2

  4. -1

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

To solve this question, the user needs to understand the basic concept of a do-while loop in Java. The loop executes the code block at least once, even if the condition is initially false. The user must evaluate the code block inside the loop to determine what value is assigned to the variable i and printed to the console.

In this code, the loop decrements the value of i by 1 until i is no longer greater than 2. Since i is initially 1, it will be decremented to 0 before the condition fails and the loop ends. Therefore, the correct answer is:

The Answer is: A. 0