Multiple choice java

What is output of the above program?

class conditional {
 public static void main(String args[]) {
   int i = 20;
   int j = 55;
   int z = 0;
   z = i < j ? i : j; // ternary operator
   System.out.println("The value assigned is " + z);
 }
}

  1. The value assigned is 20

  2. The value assigned is 60

  3. The value assigned is 30

  4. The value assigned is 50

  5. The value assigned is 40

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The ternary operator evaluates the condition (i < j). Since 20 is less than 55, the condition is true. The operator returns the first value after the question mark, which is 'i' (20). Therefore, z becomes 20, and the program prints 'The value assigned is 20'.