-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSorter.java
54 lines (49 loc) · 1.52 KB
/
Sorter.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
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Arrays;
class Sorter{
public void sort(String [] numbers){
for (int counter=0;counter<numbers.length;counter++ ) {
for (int index=0;index<numbers.length-1;index++) {
if(numbers[index].compareTo(numbers[index+1])>0){
String temp=numbers[index];
numbers[index]=numbers[index+1];
numbers[index+1]=temp;
}
}
}
}
}
class Main{
public static void main(String[] args) {
String[] numbers=new String[]{"kartik"};
System.out.println(Arrays.toString(numbers));
Sorter sorter=new Sorter();
sorter.sort(numbers);
System.out.println(Arrays.toString(numbers));
}
}
//import java.util.Arrays;
//
//class Sorter{
// public void sort(int [] numbers){
// for (int counter=0;counter<numbers.length;counter++ ) {
// for (int index=0;index<numbers.length-1;index++) {
// if(numbers[index]>numbers[index+1]){
// int temp=numbers[index];
// numbers[index]=numbers[index+1];
// numbers[index+1]=temp;
// }
// }
// }
//
// }
//}
//class Main{
// public static void main(String[] args) {
// int[] numbers=new int[]{9,2,3,4,5,6,7,8,1};
// System.out.println(Arrays.toString(numbers));
// Sorter sorter=new Sorter();
// sorter.sort(numbers);
// System.out.println(Arrays.toString(numbers));
//
// }
//}