Using Ternary Operator
We can also use ternary operator (? :) to perform the task of if...else statement. It is a
shorthand way to check the condition. If the condition is true, the result of ? is
returned. But, if the condition is false, the result of : is returned.
Example:
1. public class IfElseTernaryExample {
2. public static void main(String[] args) {
3. int number=13;
4. //Using ternary operator
5. String output=(number%2==0)?"even number":"odd number";
6. [Link](output);
7. }
8. }