Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class AMinerTask {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, Integer> quantity = new LinkedHashMap<>();
- String resource = scanner.nextLine();
- while (!resource.equals("stop")) {
- int value = Integer.parseInt(scanner.nextLine());
- if (!quantity.containsKey(resource)) {
- quantity.put(resource, value);
- } else {
- int currentQuantity = quantity.get(resource);
- quantity.put(resource, currentQuantity + value);
- }
- resource = scanner.nextLine();
- }
- quantity.forEach((key, value) -> System.out.println
- (key + " -> " + value));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment