Advertisement
Guest User

NewCodePopulationCounter

a guest
Nov 10th, 2015
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. package Problem04;
  2.  
  3. import java.util.HashMap;
  4. import java.util.LinkedHashMap;
  5. import java.util.Scanner;
  6.  
  7. public class PopulationCounter {
  8. public static void main(String[] args) {
  9. Scanner Console = new Scanner(System.in);
  10. String line = Console.nextLine();
  11.  
  12. LinkedHashMap<String, HashMap<String, Long>> Map = new LinkedHashMap<>();
  13.  
  14. while (!line.equals("report")) {
  15. String[] strArray = Console.nextLine().split("\\|+");
  16. String city = strArray[0];
  17. String country = strArray[1];
  18. Long population = Long.parseLong(strArray[2]);
  19.  
  20. if (!Map.containsKey(city)) {
  21. Map.put(city, new LinkedHashMap<>());
  22. }
  23.  
  24. Map.get(city).put(country, population);
  25.  
  26. line = Console.nextLine();
  27. }
  28. System.out.println(Map);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement