Advertisement
IrinaIgnatova

Miner Task

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