Skip to content

Commit c0f07f3

Browse files
authored
Array programs
find second maximum number of an array a[n-2];
1 parent f050736 commit c0f07f3

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Second_max.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package work;
2+
3+
import java.util.Scanner;
4+
5+
public class Second_max {
6+
7+
public static void main(String[] args) {
8+
// TODO Auto-generated method stub
9+
//find second maximum of an array:
10+
int n,temp;
11+
Scanner s=new Scanner(System.in);
12+
System.out.println("enter the element:");
13+
n=s.nextInt();
14+
System.out.println("enter the all element:");
15+
int a[]=new int[n];
16+
for(int i=0;i<n;i++)
17+
{
18+
a[i]=s.nextInt();
19+
}
20+
for(int i=0;i<n;i++)
21+
{
22+
for(int j=i+1;j<n;j++)
23+
{
24+
if(a[i]>a[j])
25+
{
26+
temp=a[i];
27+
a[i]=a[j];
28+
a[j]=temp;
29+
}
30+
}
31+
}
32+
System.out.println("second maximum: "+a[n-2]);
33+
}
34+
35+
}

0 commit comments

Comments
 (0)