-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargest_num.java
More file actions
47 lines (42 loc) · 1.21 KB
/
Largest_num.java
File metadata and controls
47 lines (42 loc) · 1.21 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
43
44
45
46
47
import java.util.Scanner;
public class Largest_num {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println(" Input numbers a b and c:");
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
// Q. print the largest of the three numbers :
//method 1
System.out.println(" Input numbers a b and c:");
int max1 = a;
if (b > max1) {
max1 = b;
}
if (c > max1) {
max1 = c;
}
System.out.println("maximum is: " + max1);
// Method 2
System.out.println(" Input numbers a b and c:");
a = in.nextInt();
b = in.nextInt();
c = in.nextInt();
int max2 =0;
if ( a > b){
max2 = a ;
}
else { max2 = b;}
if (c > max2){
max2 = c;
}
System.out.println("maximum is: " + max2);
// method 3
System.out.println(" Input numbers a b and c:");
a = in.nextInt();
b = in.nextInt();
c = in.nextInt();
int max = Math.max(c , Math.max(a,b));
System.out.println("maximum is: " + max);
}
}