-
Notifications
You must be signed in to change notification settings - Fork 0
/
practical24.java
41 lines (34 loc) · 1.07 KB
/
practical24.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
32
33
34
35
36
37
38
39
40
41
import java.util.Arrays;
import java.util.Scanner;
public class practical24 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the no of elements in a array");
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
System.out.print("Enter the index to find smallest & greatest k digit at the index : ");
int k = sc.nextInt();
int a = k;
k = k - 1;
System.out.print("The Smallest at " + a + " is :- ");
for (int i = 0; i < n; i++) {
if (i == k) {
System.out.println(arr[i]);
}
}
int[] b = new int[n];
for (int i = n - 1, j = 0; i >= 0; i--, j++) {
b[j] = arr[i];
}
System.out.print("The Largest at " + a + " is :- ");
for (int i = 0; i < n; i++) {
if (i == k) {
System.out.println(b[i]);
}
}
}
}