What is ternary operator? - ICSE Java Expert

Breaking

ICSE Java Expert

Learn Java for school

Unordered List

WELCOME

Monday, August 06, 2018

What is ternary operator?


Ternary operators operate on three expressions.
Ternary operators are used to evaluate relational/conditional expressions.
Ternary operators can be used as a substitute of if else condition.

Syntax:
result = (condition to evaluate)?code to execute when condition is true:code to execute when the condition is false;

Example:
String bike = (5<6)?"Honda":"Yamaha";
In the above example the string variable bike will get the value Honda because the condition 5<6 will evaluate to true.

Question:



Program:



Output:



Video:

No comments:

Post a Comment