forked from rmkcodingclub/AmazonProblems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem16.java
45 lines (38 loc) · 791 Bytes
/
problem16.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
/**
Solved by
Chandhiny, IT dept.
*/
import java.util.Arrays;
import java.util.Scanner;
public class second_largest
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int a=s.nextInt();
int b=s.nextInt();
int first,second;
if(a>b)
{
first=a;second=b;
}
else
{
first=b;
second=a;
}
for(int i=2;i<n;i++)
{
a=s.nextInt();
if(a<first && a>second)
second=a;
else if(a>first)
{
second=first;
first=a;
}
}
System.out.println(second);
}
}