-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab4.java
39 lines (35 loc) · 914 Bytes
/
Lab4.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
import java.lang.NullPointerException;
public class Lab4{
public static void main(String[] args){
int[] a1 = {1,2,3,5,4};
int[] a2 = {5,4,3,2,1};
int[] a3 = {3,4,5,2,1};
int[] a4 = {1,2,3,4,5};
int[] a5 = {5,5,5,1,3};
int[] a6 = null;
try{
int[] b1 = sort(a1);
int[] b2 = sort(a2);
int[] b3 = sort(a3);
int[] b4 = sort(a4);
int[] b5 = sort(a5);
int[] b6 = sort(a6);
}
catch(NullPointerException e){
System.out.println("Null array entered");
}
}
public static int[] sort(int[] a){
int curr = 0;
for(int i = 0; i < a.length; i++){
for(int j = i + 1; j < a.length; j++){
if(a[j] > a[i]){
curr = a[i];
a[i] = a[j];
a[j] = curr;
}
}
}
return a;
}
}