daily pastebin goal
87%
SHARE
TWEET

Untitled

a guest Feb 24th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.javarush.task.task10.task1016;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.InputStreamReader;
  5. import java.util.ArrayList;
  6. import java.util.Collections;
  7. import java.util.HashMap;
  8. import java.util.Map;
  9.  
  10. /*
  11. Одинаковые слова в списке
  12. */
  13.  
  14. public class Solution {
  15.     public static void main(String[] args) throws Exception {
  16.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  17.  
  18.         ArrayList<String> words = new ArrayList<String>();
  19.         for (int i = 0; i < 20; i++) {
  20.             words.add(reader.readLine());
  21.         }
  22.  
  23.         Map<String, Integer> map = countWords(words);
  24.  
  25.         for (Map.Entry<String, Integer> pair : map.entrySet()) {
  26.             System.out.println(pair.getKey() + " " + pair.getValue());
  27.         }
  28.     }
  29.  
  30.     public static Map<String, Integer> countWords(ArrayList<String> list) {
  31.         HashMap<String, Integer> result = new HashMap<String, Integer>();
  32.  
  33.         for (String s : list) {
  34.             result.put(s, Collections.frequency(list, s));//напишите тут ваш код
  35.         }
  36.         return result;
  37.     }
  38.  
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top