-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeWork12Exercise.java
More file actions
29 lines (24 loc) · 1.05 KB
/
HomeWork12Exercise.java
File metadata and controls
29 lines (24 loc) · 1.05 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
package com.learnjava;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class HomeWork12Exercise {
public static int minValue(int[] values) {
return Arrays.stream(values)
.sorted()
.distinct()
.reduce(0, (subResult, currentNum) -> subResult * 10 + currentNum);
}
public static List<Integer> oddOrEven(List<Integer> integers) {
Map<Boolean, List<Integer>> map = integers.stream()
.collect(Collectors.partitioningBy(num -> num % 2 == 0));
return map.get(false).size() % 2 == 0 ? map.get(true) : map.get(false);
}
public static void main(String[] args) {
int[] arr = {1, 1, 2, 1, 4, 5, 5, 9, 8};
System.out.println("Минимальное значение по условиям задачи: " + minValue(arr));
List<Integer> intList = Arrays.asList(1, 2, 3, 7, 8, 3);
System.out.println("четные или не четные числа: " + oddOrEven(intList));
}
}