-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortingArray.java
More file actions
43 lines (36 loc) · 1.13 KB
/
Copy pathSortingArray.java
File metadata and controls
43 lines (36 loc) · 1.13 KB
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
42
43
package BeginnerJava;
import java.util.Arrays;
public class SortingArray {
public static void main(String[] args) {
int[] num = {2, 5, 4, 9, 3 ,1, 45, 263,7};
Arrays.sort(num);
int s = num.length;
// Ascending order
System.out.print("Ascending order: ");
for(int i=0; i<s; i++)
{
System.out.print(num[i] +" ");
}
System.out.println();
// Descending order
System.out.print("Descending order: ");
for(int i=s-1; i>=0; i--) {
System.out.print(num[i] +" ");
}
System.out.println();
String[] name = {"Sujon", "Likhon", "Koushik", "Abid"};
Arrays.sort(name);
int siz = name.length;
// Ascending order
System.out.print("Ascending order: ");
for(int i=0; i<siz; i++){
System.out.print(name[i] +" ");
}
System.out.println();
// Descending order
System.out.print("Descending order: ");
for(int i=siz-1; i>=0; i--) {
System.out.print(name[i] +" ");
}
}
}