Home / Programming MCQs / JAVA MCQs / Question

D

Deepak Sahoo • 10.60K Points
Tutor II

Q. What is the output of the following code?

Code:
int x = 10;
if (x < 5) {
System.out.println(“x is less than 5”);
} else if (x > 20) {
System.out.println(“x is greater than 20”);
} else {
System.out.println(“x is between 5 and 20”);
}
(A) x is less than 5
(B) x is greater than 20
(C) x is between 5 and 20
(D) Compiler error
Explanation by: Deepak Sahoo
Since x is between 5 and 20, the else block is executed and “x is between 5 and 20” is

You must be Logged in to update hint/solution

Discusssion

Login to discuss.