-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion3.java
More file actions
27 lines (24 loc) · 803 Bytes
/
question3.java
File metadata and controls
27 lines (24 loc) · 803 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
public class question3{
public static void main(String[] args) {
int a[] = {8,4,3,9,2};
a = SortArray(a);
for (int i = 0; i < a.length; i++) {
System.out.println(a[i] + " ");
}
int k = 2;
System.out.println("\nk = " +k);
System.out.println(k + "max = " + a[a.length - k]);
System.out.println(k + " min = " + a[k-1]);
}
public static int[] SortArray(int a[]) {
for(int i = 1; i <= a.length; i++){
for(int j = 0; j < a.length- i; j++){
if (a[j] > a[j+1]){
int temp = a[j];
a[j+1] = temp;
}
}
}
return a;
}
}