-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGreatestThree.java
50 lines (48 loc) · 1.1 KB
/
GreatestThree.java
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
43
44
45
46
47
48
49
50
// Program to take three numbers from the user and print the greatest number.
import java.util.Scanner;
public class GreatestThree
{
public static void main (String args[])
{
Scanner reader = new Scanner(System.in);
System.out.println("Enter Three numbers ------");
System.out.println("1st Number = ");
int n1 = reader.nextInt();
System.out.println("2nd Number = ");
int n2 = reader.nextInt();
System.out.println("3rd Number = ");
int n3 = reader.nextInt();
reader.close();
if (n1 > n2)
{
if (n1 > n3)
{
System.out.println("Greatest among " + n1 + ", " + n2 + " and " + n3 + " is " + n1);
}
else
{
System.out.println("Greatest among " + n1 + ", " + n2 + " and " + n3 + " is " + n3);
}
}
else
{
if (n2 > n3)
{
System.out.println("Greatest among " + n1 + ", " + n2 + " and " + n3 + " is " + n2);
}
else
{
System.out.println("Greatest among " + n1 + ", " + n2 + " and " + n3 + " is " + n3);
}
}
}
}
//Output:
//Enter Three numbers ------
//1st Number =
//5
//2nd Number =
//6
//3rd Number =
//3
//Greatest among 5, 6 and 3 is 6