1.

What is the use and syntax of a ternary operator ?

Answer»

A ternary operator is a type of operator that requires three operands. It is also known as conditional operator, that is represented by symbol. The use of a ternary operator is to handle the conditional statements that will produce one result out of two. It is an alternative of if-else statement. 

The syntax of a ternary operator is : 

Condition ? Operand 2: Operand 3 

Ex: System.out.println(a>b?a:b);



Discussion

No Comment Found

Related InterviewSolutions