int x = 12;
while (x < 10) {
x--;
}
System.out.print(x);
int x = 12;
while (x < 10) {
x--;
}
System.out.print(x);
What is the result?
Reveal answer
Fill a bubble to check yourself
int x = 12;
while (x < 10) {
x--;
}
System.out.print(x);
What is the result?
0
10
12
print statement never be executed
The while loop condition (x < 10) is false initially since x = 12. The loop body never executes, so x is never decremented and remains 12. The print statement outputs 12, not 0 or 10.
To answer this question, let's go through the code step by step:
x with the value 12.x < 10. Since x is initially 12, the condition is false, and the code inside the while loop will not be executed.x, which is 12.Therefore, the result of the code is 12.
The correct answer is option C.