int x = 12;
while (x < 10) {
    x--;  
}  
System.out.print(x);

What is the result?

  1. 0

  2. 10

  3. 12

  4. print statement never be executed


Correct Option: C
Explanation:

To solve this question, the user needs to know about while loop and comparison operators.

In the given code snippet, the while loop will only execute if the condition inside the parentheses is true. The code initializes the variable x to 12 and checks if it is less than 10. Since 12 is greater than 10, the condition is false, and the code inside the while loop will never execute. The print statement will execute outside of the loop, which will output the value of the variable x.

Options A, B, and C can be eliminated since none of them represent the correct value.

Option D is incorrect because the print statement will execute regardless of whether the while loop is executed or not.

Therefore, the correct answer is:

The Answer is: C. 12

Find more quizzes: