-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecond_largest_No.java
More file actions
39 lines (32 loc) · 923 Bytes
/
Copy pathSecond_largest_No.java
File metadata and controls
39 lines (32 loc) · 923 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
32
33
34
35
36
37
38
39
public class Second_largest_No {
public static void main(String[] args) {
int arr[] = {70,23,5,8,91,98};
int size = arr.length;
int temp = 0;
System.out.print("Array: ");
for(int num : arr)
{
System.out.print(num);
}
for(int i =0; i<size; i++)
{
for(int j=0;j<size-1;j++)
{
if(arr[j]>arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
System.out.print(" Sorted Array: ");
for(int num : arr)
{
System.out.print(num);
}
System.out.println("");
System.out.println("Size of the array : " + size );
System.out.println("Second Largest Element of the array : " + arr[size-2]);
}
}