Advertisement
deyanmalinov

02. A Miner Task - sout

Mar 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.LinkedHashMap;
  4. import java.util.Map;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8.     public static void main(String[] args) {
  9.         Scanner scan = new Scanner(System.in);
  10.         Map<String, Integer> goods = new LinkedHashMap<>();
  11.         String line = "";
  12.  
  13.         while (!"stop".equals(line = scan.nextLine())){
  14.             String metal = line;
  15.             int amaunt = Integer.parseInt(scan.nextLine());
  16.  
  17.             if (goods.containsKey(line)){
  18.                 goods.put(metal, goods.get(metal)+amaunt);
  19.             }else {
  20.                 goods.put(metal, amaunt);
  21.             }
  22.         }
  23. //        for (Map.Entry<String, Integer> entry : goods.entrySet()) {
  24. //            System.out.printf("%s -> %d%n", entry.getKey(), entry.getValue());
  25. //        }
  26.         /////////////////////////////////////////
  27. //        goods.entrySet().forEach(el -> {
  28. //            System.out.printf("%s -> %d\n", el.getKey(), el.getValue());
  29. //        });
  30.         /////////////////////////////////////////
  31.         goods.forEach((key, value ) -> System.out.printf("%s -> %d\n", key, value));
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement