Advertisement
desislava_topuzakova

02. A Miner Task

Mar 7th, 2021
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import com.sun.security.jgss.GSSUtil;
  2.  
  3. import java.util.*;
  4.  
  5. public class demo {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String resource = scanner.nextLine(); //ресурс или stop
  9.         //ресурс -> количество
  10.         Map<String, Integer> resourcesQuantity = new LinkedHashMap<>();
  11.         while(!resource.equals("stop")) {
  12.             int quantity = Integer.parseInt(scanner.nextLine());
  13.  
  14.             //да нямам такъв ресурс
  15.             if(!resourcesQuantity.containsKey(resource)) {
  16.                 resourcesQuantity.put(resource, quantity);
  17.             } else {
  18.                 resourcesQuantity.put(resource, resourcesQuantity.get(resource) + quantity);
  19.             }
  20.  
  21.  
  22.  
  23.             resource = scanner.nextLine();
  24.         }
  25.  
  26.         resourcesQuantity.forEach((k, v) -> System.out.println(k + " -> " + v));
  27.  
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement