Question discussion

What is the output of the above code snippet( Assume that it is written inside main() function )?

359025Medium DSSSB TGT Computer Science 0 replies 0 views
0
What is the output of the above code snippet( Assume that it is written inside main() function )?
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");
    }
}
  • Ac is the largest
  • Bb is the largest
  • Ca is the largest
  • DCompilation error
Correct answer: B

Explanation

a = 4, b = 8, c = 6. a > b is false, so the else block runs. There b > c (8 > 6) is true, so it prints "b is the largest".

Discussion 0

Nobody has replied yet. Start the discussion!