blob: ba0eeb0fa388fa06f9af3c926c2b1cbc624808b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
import java.util.HashMap;
import java.util.Map;
public class Ch2 {
public static void main(String[] args) {
System.out.println(odd_letters("weekly"));
System.out.println(odd_letters("perl"));
System.out.println(odd_letters("challenge"));
}
private static boolean odd_letters(String s) {
Map<Character, Integer> h = new HashMap<>();
for (var c : s.toCharArray()) h.merge(c, 1, Integer::sum);
return h.values().stream().allMatch(a -> a % 2 != 0);
}
}
|