Question 1
What is the output of the following program? ```java public class Main { public static void main(String[] args) { int i, j; for (i = 0, j = 5; i < j; i++, j--) { } System.out.println(i + " " + j); } } ```
A. 3 2Correct answer
Comma lists are legal in init and update; tracing (0,5)->(1,4)->(2,3) then i=3, j=2 makes 3 < 2 false, so it exits at 3 2.
B. 2 3
This swaps the two values; i ends at 3 and j at 2, not the reverse.
C. 5 0
These are the initial values before any iteration; the loop runs several times, changing both i and j.
D. Compilation fails because a for loop cannot have two update expressions
A for loop may have multiple comma-separated update expressions, so this compiles.
Explanation
Comma-separated lists are legal in both the init and update sections (`Compilation fails because a for loop cannot...` is wrong). Trace the pairs: (0,5) → (1,4) → (2,3) → after the third update i=3, j=2 and 3 < 2 is false, so the loop exits with i=3, j=2.