forked from aromalsanthosh/Java-Lab-S3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargestOf.java
More file actions
66 lines (60 loc) · 1.38 KB
/
LargestOf.java
File metadata and controls
66 lines (60 loc) · 1.38 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.Scanner;
public class LargestOf {
public void largestOf(int x,int y){
if (x>y) {
System.out.println(x+" is largest");
}
else if(x==y) {
System.out.println(x+" = "+y);
}
else {
System.out.println(y+" is largest");
}
}
public void largestOf(int x,int y,int z) {
if (x>y && x>z) {
System.out.println(x+" is largest");
}
else if(y>z) {
System.out.println(y+" is largest");
}
else {
System.out.println(z+" is largest");
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
LargestOf ob1 = new LargestOf();
int ch = 0;
while (ch!=3) {
System.out.println("Enter a choice :");
System.out.println("1.Largest of 2 Numbers");
System.out.println("2.Largest of 3 Numbers");
System.out.println("3.Exit");
ch = sc.nextInt();
switch (ch) {
case 1:
System.out.println("Enter first no:");
int a = sc.nextInt();
System.out.println("Enter second no:");
int b = sc.nextInt();
ob1.largestOf(a, b);
break;
case 2:
System.out.println("Enter first no:");
int a1 = sc.nextInt();
System.out.println("Enter second no:");
int b1 = sc.nextInt();
System.out.println("Enter third no:");
int c1 = sc.nextInt();
ob1.largestOf(a1, b1, c1);
break;
case 3:
return;
default:
System.out.println("Enter correct choice");
break;
}
}
}
}