Skip to content

Commit 67cea87

Browse files
committed
initial commit
1 parent 1f5ebf6 commit 67cea87

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package LogicBuilding;
2+
3+
import java.util.Arrays;
4+
5+
/**
6+
* Created by ChandanKrv on 12 September, 2024.
7+
* --------------------------------------------
8+
* Q. Problem Statement :
9+
* Find the second smallest and second largest element in an array
10+
*/
11+
public class _7_2ndLargestAndSmallest {
12+
public static void main(String[] args) {
13+
int[] arr = {4, 3, 2, 1, -8, 12, 45, 90};
14+
int n = arr.length;
15+
16+
Arrays.sort(arr);
17+
System.out.println("Array: " + Arrays.toString(arr));
18+
System.out.println("2nd Smallest: " + arr[1]);
19+
System.out.println("2nd Largest: " + arr[n - 2]);
20+
21+
}
22+
23+
}

0 commit comments

Comments
 (0)