Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class OddOccurrences {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] sequence = scanner.nextLine().split(" ");
- LinkedHashMap<String, Integer> count = new LinkedHashMap<>();
- for (String sequenceOfWords : sequence) {
- String wordLowerCase = sequenceOfWords.toLowerCase(Locale.ROOT);
- if (count.containsKey(wordLowerCase)) {
- count.put(wordLowerCase, count.get(wordLowerCase) + 1);
- } else {
- count.put(wordLowerCase, 1);
- }
- }
- ArrayList<String> oddElement = new ArrayList<>();
- for (var entry : count.entrySet()) {
- if (entry.getValue() % 2 == 1) {
- oddElement.add(entry.getKey());
- }
- }
- for (int i = 0; i < oddElement.size(); i++) {
- System.out.print(oddElement.get(i));
- if (i < oddElement.size() - 1) {
- System.out.print(", ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment