int a = 4, b = 8, c = 6; if (a > b) {
int a = 4, b = 8, c = 6;
if (a > b) {
if (a > c) {
System.out.println("a is the largest");
} else if (b > c) {
System.out.println("b is the largest");
} else {
System.out.println("c is the largest");
}
} else {
if (b > c) {
System.out.println("b is the largest");
} else {
System.out.println("c is the largest");
}
}
What is the output of the above code snippet( Assume that it is written inside main() function
)?
Show answerHide answer
Correct answer: (B) b is the largest
Explanation
a > b (4 > 8) is false, so the outer else block runs. There b > c (8 > 6) is true, so "b is the largest" is printed.