Computer Applications

What will be the output of the following code?

int size = 2;
if (size < 0)
    System.out.println("Small"); 
else if (size == 0)
    System.out.println("Medium");
else
    System.out.println("Large");
  1. Small
  2. Large
  3. Medium
  4. Runtime error

Java Conditional Stmts

31 Likes

Answer

Large

Reason — Since size > 0, hence the conditions of if and else if are false. Thus, the else block will be executed and "Large" will be printed on the screen.

Answered By

11 Likes


Related Questions