-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomComparator.java
More file actions
40 lines (30 loc) · 1.07 KB
/
CustomComparator.java
File metadata and controls
40 lines (30 loc) · 1.07 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
package CustomComparator;
import java.text.CollationElementIterator;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class CustomComparator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] input = scanner.nextLine().split("\\s+");
int[] evenNums = Arrays.stream(input)
.filter(x -> x.length() > 0)
.mapToInt(Integer::parseInt)
.filter(x -> x % 2 == 0)
.toArray();
int[] oddNums = Arrays.stream(input)
.filter(x -> x.length() > 0)
.mapToInt(Integer::parseInt)
.filter(x -> x % 2 != 0)
.toArray();
Arrays.sort(evenNums);
Arrays.sort(oddNums);
for (int evenNum : evenNums) {
System.out.printf("%d ",evenNum);
}
for (int oddNum : oddNums) {
System.out.printf("%d ",oddNum);
}
}
}