-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGreater.java
More file actions
33 lines (25 loc) · 1006 Bytes
/
Greater.java
File metadata and controls
33 lines (25 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//Q3. Write a program to find a greater number among given three numbers using a) ternary operator and b)nested if.
public class Greater {
public static void main(String[] args) {
int a = 10, b = 14, c = 19;
int greatestnum = (a > b) ? ((a > c) ? a : c) : ((b < c) ? b : c);
System.out.println("Greatest number is :" + greatestnum);
}
}
// public class Greater {
// public void GreaterNum(int a, int b, int c) {
// if (a == b && b == c) {
// System.out.println("All numbers are same");
// } else if (a > b && a > c) {
// System.out.println("a is Greater among Three");
// } else if (b > a && b > c) {
// System.out.println("b is Greater among Three");
// } else {
// System.out.println("c is Greater among Three");
// }
// }
// public static void main(String[] args) {
// Greater great = new Greater();
// great.GreaterNum(30, 30, 30);
// }
// }