How does the ternary Operator Works?
The Ternary Operator contains three operands with
"? :". Based on the return type it will give the value.
operand1 ? operand2 : operand3
Ternary Operator Syntax:
boolean expression ? value1 : value2 ;
The first operand is a boolean expression; if the expression is true then the value of the second operand is returned otherwise the value of the third operand is returned:
Here if operand1 is true, operand2 is returned.
operand1 must be a boolean type
"? :". Based on the return type it will give the value.
operand1 ? operand2 : operand3
Ternary Operator Syntax:
boolean expression ? value1 : value2 ;
The first operand is a boolean expression; if the expression is true then the value of the second operand is returned otherwise the value of the third operand is returned:
Here if operand1 is true, operand2 is returned.
operand1 must be a boolean type