Question 1
What does this print? ```java public class Main { public static void main(String[] args) { int i = 0; do { System.out.print(i); i++; } while (i < 3); } } ```
A. 0123
Needs a fourth pass, but the condition fails once the counter reaches 3, so 3 is never printed.
B. 012Correct answer
The body prints the current value then increments on each pass; after printing 2 the counter becomes 3, and 3 < 3 is false, ending the loop. (JLS §14.13)
C. (no output)
A do-while body always executes at least once, so the output is never empty.
D. 123
Would require incrementing before printing, but the body prints first and then increments.
Explanation
The do-while loop evaluates its condition after each pass, so the body runs — printing the current value and then incrementing — before the test decides whether to repeat. Starting from zero it prints 0, 1, 2, and after the value becomes 3 the condition fails and the loop stops. The output is 012. (JLS 17 §14.13 — the do statement)