Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package associativeArrays;
- import java.util.ArrayList;
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class P03OddOccurrences {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] inputArr = scanner.nextLine().split(" ");
- LinkedHashMap<String, Integer> wordsMap = new LinkedHashMap<>();
- for (String word : inputArr) {
- word = word.toLowerCase();
- wordsMap.putIfAbsent(word, 0);
- wordsMap.put(word, wordsMap.get(word) + 1);
- // -v.01-
- // if (wordsMap.containsKey(word)) {
- // wordsMap.put(word, wordsMap.get(word) + 1);
- // } else {
- // wordsMap.put(word, 1);
- // }
- // -v.01-
- // if (!wordsMap.containsKey(word)) {
- // wordsMap.put(word, 0);
- // }
- //
- // wordsMap.put(word, wordsMap.get(word) + 1);
- }
- ArrayList<String> resultList = new ArrayList<>();
- for (Map.Entry<String, Integer> entry : wordsMap.entrySet()) {
- if (entry.getValue() % 2 != 0) {
- resultList.add(entry.getKey());
- }
- }
- System.out.println(String.join(", ", resultList));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement