What does the following code output?
String v = ""; while (v.length() != 2) v+="a"; System.out.println(v);
A.
Immediately after v is initialized, the loop condition is checked.
The variable v is of length 0, which is not equal to 2 so the loop is entered.
In the loop body, v becomes length 1 with contents "a".
The loop index is checked again and now 1 is not equal to 2.
The loop is entered and v becomes length 2 and contains "aa".
Then the loop index is checked again.
Since the length is now 2, the loop is completed and aa is output.
Option A is correct.