-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_sorting.java
More file actions
31 lines (26 loc) · 894 Bytes
/
Copy pathcmd_sorting.java
File metadata and controls
31 lines (26 loc) · 894 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
28
29
30
31
/* Reading the array of numbers through command line and sort in ascending order */
package Cmdline_Sorting;
public class cmd_sorting {
public static void main(String[] args){
int[] a = new int[10];
for (int i = 0; i < args.length; i++) {
a[i] = Integer.parseInt(args[i]);
}
System.out.println("array before sorting: ");
for (int i = 0; i < args.length; i++){
System.out.print(a[i]);
}
for (int i = 0; i < args.length; i++) {
for (int k = i + 1; k < args.length; k++) {
if (a[i] > a[k]) {
int temp = a[i];
a[i] = a[k];
a[k] = temp;
}
}
}
System.out.println("array after sorting: ");
for (int i = 0; i < args.length; i++)
System.out.print(a[i]);
}
}