Page 126 - CA_Blue( J )_Class10
P. 126
15 if(a>b)
16 {
17 if(a>c)
18 System.out.println(a + " is greater than " + b + " and " + c);
19 else
20 System.out.println(c + " is greater than " + a + " and " + b);
21 }
22 else
23 {
24 if(b>c)
25 System.out.println(b + " is greater than " + a + " and " + c);
26 else
27 System.out.println(c + " is greater than " + a + " and " + b);
28 }
29 System.out.println("--------------------------");
30 }
31 }
You will get the following output:
7.3 TERNARY OPERATOR
Ternary operator is another way of representing the if statement. It is a special operator with two symbols and
containing three operands or expressions. Syntax of the ternary operator is:
Result = (Condition)? Statement1 : Statement 2;
If the conditional expression evaluates to true, then Statement1 will execute otherwise Statement 2 will execute.
Program 7 To input a number and print whether it is greater than 40 or not.
1 import java.util.*;
2 class greater_than_forty
3 {
4 public static void main ()
124124 Touchpad Computer Applications-X

