Advertisement
romancha

task_815

Jul 31st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3.  
  4. /**
  5.  * Created by astures on 31.07.17.
  6.  */
  7. public class test
  8. {
  9.     public static HashMap<String, String> createMap() {
  10.         //напишите тут ваш код
  11.         HashMap<String, String> map = new HashMap<>();
  12.         for(int i = 0; i < 10; i++) {
  13.             map.put("lastName" + i, "firstName" + i);
  14.         }
  15.  
  16.         return map;
  17.     }
  18.  
  19.     public static int getCountTheSameFirstName(HashMap<String, String> map, String name) {
  20.         //напишите тут ваш код
  21.         int count = 0;
  22.         for (Map.Entry<String, String> pair : map.entrySet()) {
  23.             String value = pair.getValue();
  24.             if (value.equals(name))
  25.                 count++;
  26.         }
  27.         return count;
  28.     }
  29.  
  30.     public static int getCountTheSameLastName(HashMap<String, String> map, String lastName) {
  31.         //напишите тут ваш код
  32.         for (Map.Entry<String, String> pair : map.entrySet()) {
  33.             String key = pair.getKey();
  34.             if (key.equals(lastName))
  35.                 return 1;
  36.         }
  37.         return 0;
  38.     }
  39.  
  40.     public static void main(String[] args) {
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement