Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- LinkedHashMap<String, Integer> table = new LinkedHashMap<>();
- String input = scanner.nextLine();
- while (!input.equals("stop")) {
- String resource = input;
- Integer quantity = Integer.parseInt(scanner.nextLine());
- if (!table.containsKey(resource)) {
- table.put(resource, quantity);
- } else {
- int currentQuantity = table.get(resource);
- table.put(resource, currentQuantity + quantity);
- }
- input = scanner.nextLine();
- }
- for (Map.Entry<String, Integer> entry : table.entrySet()) {
- System.out.printf("%s -> %d%n", entry.getKey(), entry.getValue());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement