Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] words = scanner.nextLine().split(" ");
- LinkedHashMap<String, Integer> counts = new LinkedHashMap<>();
- for (String word : words) {
- String wordsOnLowerCAse = word.toLowerCase();
- if (counts.containsKey(wordsOnLowerCAse)) {
- counts.put(wordsOnLowerCAse, counts.get(wordsOnLowerCAse) + 1);
- } else {
- counts.put(wordsOnLowerCAse, 1);
- }
- }
- ArrayList<String> odds = new ArrayList<>();
- for (Map.Entry<String, Integer> entry : counts.entrySet()) {
- if (entry.getValue() % 2 == 1) {
- odds.add(entry.getKey());
- }
- }
- for (int i = 0; i < odds.size(); i++) {
- System.out.print(odds.get(i));
- if (i < odds.size() - 1) {
- System.out.print(", ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement