Page 89 - CA_Blue( J )_Class9
P. 89
Input: You will get the following output:
5.2.3 Ternary Operator
An operator that works with three operands or expressions is called ternary operator. There is only one ternary
operator in Java. It is also known as Conditional Operator. For example, (a>b)? a: b.
Where, (a>b) is the condition, a and b is the expression or operands, and ?: is the ternary operator.
Write a program using ternary operator to find the greatest number out of the two given
Program 4
numbers.
1 class ternary
2 {
3 public static void main(String args[])
4 {
5 int a = 7, b = 13;
6 int grt;
7 grt = (a > b) ? a: b;
8 System.out.println("The greater number is: "+grt);
9 }
10 }
You will get the following output:
Operators in Java 87

