Advertisement
Guest User

Untitled

a guest
May 26th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. package Exercice;
  2.  
  3. import java.util.*;
  4.  
  5. public class MinerTask_06 {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9.  
  10. Map<String,Integer> resources=new LinkedHashMap<>();
  11.  
  12.  
  13. String input;
  14.  
  15. int count = 0;
  16. while (!"stop".equals(input=scanner.nextLine())){
  17. if (count%2==0){
  18. if (!resources.containsKey(input)){
  19. resources.put(input,scanner.nextInt());
  20. }else {
  21. resources.put(input,resources.get(input)+scanner.nextInt());
  22. }
  23. }
  24. count++;
  25. }
  26.  
  27. for (Map.Entry<String,Integer> kvp : resources.entrySet()){
  28. System.out.println(String.format(
  29. "%s -> %d",kvp
  30. .getKey(),kvp.getValue()
  31. ));
  32. }
  33. }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement