- Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathFirstThreeLargest.java
More file actions
Latest commit
31 lines (31 loc) · 662 Bytes
/
Copy pathFirstThreeLargest.java
File metadata and controls
31 lines (31 loc) · 662 Bytes
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
publicclassFirstThreeLargest{
publicstaticvoidMain(Stringargs[])
{
intarr[] = {2,7,9,3,6,1,11,8};
solve(arr);
}
publicstaticvoidsolve(intarr[])
{
intn=arr.length;
intfirst = Integer.MIN_VALUE, second=Integer.MIN_VALUE,third=Integer.MIN_VALUE;
for(inti=0;i<n;i++)
{
if(first<=arr[i])
{
third = second;
second = first;
first = arr[i];
}
elseif(second<=arr[i])
{
third = second;
second = arr[i];
}
elseif(third<=arr[i])
{
third = arr[i];
}
}
System.out.println(first + " " + second + " "+ third);
}
}