What will be the output of the following Java code? public class DoWhileExample {
What will be the output of the following Java code? public class DoWhileExample {
public static void main(String[] args) {
int x = 10;
do {
System.out.println("x = " + x);
x++;
} while (x < 13);
}
}
Show answerHide answer
Correct answer: (A) x = 10 x = 11 x = 12
Explanation
A do-while body runs before the test: it prints x = 10, 11 and 12, and stops when x becomes 13 because 13 < 13 is false.