We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f050736 commit c0f07f3Copy full SHA for c0f07f3
Second_max.java
@@ -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
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