Advertisement
Dido09

5.4b - Football Match

May 8th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class FootballMatch {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner scanner = new Scanner(System.in);
  8. HashMap<String, Integer> goals = new HashMap<String, Integer>();
  9.  
  10. while(true) {
  11. String[] input = scanner.nextLine().split(" - ");
  12.  
  13. if(input[0].equalsIgnoreCase("end of season")) {
  14. break;
  15. }
  16.  
  17. if(goals.containsKey(input[0])) {
  18. goals.put(input[0], goals.get(input[0])+Integer.parseInt(input[1]));
  19. } else {
  20. goals.put(input[0], Integer.parseInt(input[1]));
  21. }
  22. }
  23.  
  24. ArrayList<String> keys = new ArrayList<String>(goals.keySet());
  25. Collections.sort(keys);
  26.  
  27. for(String s : keys) {
  28. System.out.println(s+" -> "+goals.get(s));
  29. }
  30.  
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement