ICSE Class 10 Computer Applications Question 7 of 26

Operators in Java — Question 7

Back to all questions
7
Question

Question 7

What is the use and syntax of a ternary operator?

Answer

Ternary operator is used to check if a condition is true and false. Depending on whether the condition tests true or false, expression 1 or expression 2 is evaluated. Its syntax is:

boolean-expression ? expression1 : expression2;