-
Notifications
You must be signed in to change notification settings - Fork 0
/
Execute.java
84 lines (83 loc) · 2.49 KB
/
Execute.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.util.Scanner;
class Compare
{
public <E extends Comparable<E>> E max(E[] list)
{
E maxvalue=list[0];
for(int i=1;i<list.length;i++)
{
if(maxvalue.compareTo(list[i])<0)
maxvalue=list[i];
}
return maxvalue;
}
}
public class Execute
{
public static void main(String args[])
{
Scanner reader=new Scanner(System.in);
Compare ob=new Compare();
int choice,ch,n;
do
{
System.out.println("\t\tElements type");
System.out.println("1.Integer\n2.Float\n3.Double\n4.String\n5.Character");
System.out.print("Enter your choice: ");
choice=reader.nextInt();
switch(choice)
{
case 1:
System.out.print("Enter the array size: ");
n=reader.nextInt();
Integer[] numbers=new Integer[n];
System.out.print("Enter the elements: ");
for(int i=0;i<n;i++)
numbers[i]=reader.nextInt();
System.out.println("The maximum element in the Integer array is: "+ob.max(numbers));
break;
case 2:
System.out.print("Enter the array size: ");
n=reader.nextInt();
Float[] numbers1=new Float[n];
System.out.print("Enter the elements: ");
for(int i=0;i<n;i++)
numbers1[i]=reader.nextFloat();
System.out.println("The maximum element in the Float array is: "+ob.max(numbers1));
break;
case 3:
System.out.print("Enter the array size: ");
n=reader.nextInt();
Double[] numbers2=new Double[n];
System.out.print("Enter the elements: ");
for(int i=0;i<n;i++)
numbers2[i]=reader.nextDouble();
System.out.println("The maximum element in the Double array is: "+ob.max(numbers2));
break;
case 4:
System.out.print("Enter the array size: ");
n=reader.nextInt();
String[] s=new String[n];
System.out.print("Enter the elements: ");
for(int i=0;i<n;i++)
s[i]=reader.next();
System.out.println("The maximum element in the String array is: "+ob.max(s));
break;
case 5:
System.out.print("Enter the array size: ");
n=reader.nextInt();
Character[] c=new Character[n];
System.out.print("Enter the elements: ");
for(int i=0;i<n;i++)
c[i]=reader.next().charAt(0);
System.out.println("The maximum element in the Float array is: "+ob.max(c));
break;
default:
System.out.println("Wrong choice!!");
}
System.out.println("Do you want to continue?<0/1>: ");
ch=reader.nextInt();
}while(ch==1);
System.out.println("Thank you!!");
}
}