Ternary (Conditional) Operators

The conditional operator (? :) is a ternary operator. This operator needs 3 operands to perform the operation.

Syntax:

Variable = <test expression> ? <expression 1> : <expression 2>


The conditional operator works as follows:

 Test Expression is Condition

 Expression 1 is Statement Followed if Condition is True

 Expression 2 is Statement Followed if Condition is False

The conditional operator (? :) is a ternary operator. This operator needs 3 operands to perform the operation.




Java : Ternary (Conditional) Operators Program List




Program [1]

Write a program using ternary operator to check whether 27 is a multiple of 3 or not.


View Solution