-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGreatestOfThree.java
More file actions
42 lines (30 loc) · 1.12 KB
/
Copy pathGreatestOfThree.java
File metadata and controls
42 lines (30 loc) · 1.12 KB
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
33
34
35
36
37
38
39
40
41
42
package CodingPractice;
import java.util.Scanner;
public class GreatestOfThree {
public static void main(String[] args) {
// Greatest of Three numbers
Scanner sc = new Scanner(System.in);
System.out.println("Enter first number : ");
int num1 = sc.nextInt();
System.out.println("Enter second number : ");
int num2 = sc.nextInt();
System.out.println("Enter third number : ");
int num3 = sc.nextInt();
int result = 0;
// Technique 01 - if else if
if (num1 > num2 && num1 > num3)
result = num1;
else if (num2 > num3)
result = num2;
else
result = num3;
System.out.println(result + " is greatest of three.");
// Technique 02 - Ternary operator
result = num1 > num2 && num1 > num3 ? num1 : num2 > num3 ? num2 : num3;
System.out.println(result + " is greatest of three.");
// Technique 03 - In-built max method
result = Math.max(Math.max(num1, num2), num3);
System.out.println(result + " is greatest of three.");
sc.close();
}
}