-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSortingTheOddPositionArrayMethod.java
53 lines (47 loc) · 1.47 KB
/
SortingTheOddPositionArrayMethod.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
package roar;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class SortingTheOddPositionArrayMethod {
public void sorter(Object... array) {
ArrayList<Integer> b = new ArrayList<>();
int z = 0;
for (int i = 0; i < array.length; i++){
if ((Integer) array[i] % 2 != 0)
b.add(i);
}
int c[] = new int[b.size()];
for (int i = 0; i < b.size(); i++) {
int f = b.get(i);
c[i] =(int) array[f];
}
Arrays.sort(c);
for (int i = 0; i < b.size(); i++) {
int i1 = b.get(i);
array[i1] = c[i];
}
System.out.print("[");
for (int f = 0; f < array.length; f++) {
if (f == array.length - 1){
System.out.print(array[f]);
break;
}
System.out.print(array[f] + ", ");
}
System.out.println("]");
}
public static void main(String[] args) {
ArrayList<Integer> ls = new ArrayList<>();
Scanner f = new Scanner(System.in);
while (true){
int v = f.nextInt();
if(v == 0){
break;
}
ls.add(v);
}
SortingTheOddPositionArrayMethod l = new SortingTheOddPositionArrayMethod();
l.sorter(ls.toArray());
// System.out.println(GenM.maximum("Ahmed",4));
}
}