-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSecondmax.java
31 lines (29 loc) · 909 Bytes
/
Secondmax.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
//PROGRAM THAT FINDS SECOND MAX NUMBER IN ARRAY.
import java.util.Scanner;
public class Secondmax{
public static void main (String[] args) {
Scanner get=new Scanner(System.in);
System.out.println("enter the length of matrix:");
int len=get.nextInt();
int array[]=new int[len];
System.out.println("enter a number:");
array[0]=get.nextInt();
int max = array[0];
for(int i=1;i<len;i++){
System.out.println("enter a number:");
array[i]=get.nextInt();
}
int secondmax=0;
for(int i=0;i<len;i++){
if(max<array[i]){
max=array[i];
}
}
for(int i=0;i<len;i++){
if((secondmax<array[i])&&(array[i]<max)){
secondmax=array[i];
}
}
System.out.printf("second max = %d",secondmax);
}
}