forked from sonal2203/SimpleCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleCode2
More file actions
53 lines (40 loc) · 1.05 KB
/
Copy pathSimpleCode2
File metadata and controls
53 lines (40 loc) · 1.05 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
public class largestinarrar {
public static int largestinarray(int[] input) {
int max=Integer.MIN_VALUE;
for(int i=0; i<input.length; i++) {
if (input[i]>max) {
max=input[i];
}
}
return max;
}
public static int Secondlargest(int[] input) {
int largest=largestinarray(input);
int max2=Integer.MIN_VALUE;
for(int i=0; i<input.length; i++) {
if(input[i]>max2 && input[i]!=largest) {
max2=input[i];
}
}
return max2;
}
public static int thirdlargest(int[] input) {
int largest=largestinarray(input);
int largest1=Secondlargest(input);
int max3=Integer.MIN_VALUE;
for(int i=0; i<input.length; i++) {
if(input[i]>max3 && input[i]!=largest1 &&input[i]!=largest) {
max3=input[i];
}
}
return max3;
}
public static void main(String[] args) {
int input[]= {2,4,3,5,6,7,8};
int secondLargest = Secondlargest(input);
System.out.println(largestinarray(input));
System.out.println( secondLargest);
System.out.print(thirdlargest(input));
// TODO Auto-generated method stub
}
}