Multiple choice

How can the under given statement be written?If (p<100) Flag = 10; Else Flag = 20;

  1. flag=(p<100) ? 10 : 20;

  2. flag=(p<100) : 10 ? 20 ;

  3. flag=(p<100) : 20 ? 10 ;

  4. flag=(p<100) ? 20 : 10;

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

The ternary operator in Java follows the syntax: condition ? expression_if_true : expression_if_false. Option A correctly maps the if-else logic to this format.