-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAMinerTask.java
More file actions
38 lines (30 loc) · 1.03 KB
/
Copy pathAMinerTask.java
File metadata and controls
38 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package mapsLabdaStreamAPI;
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);
String inputLine = scanner.nextLine();
int counter = 0;
String item = "";
Map<String,Integer> itemsMap = new LinkedHashMap<>();
while(!inputLine.equals("stop")){
counter ++;
if(counter % 2 != 0){
item = inputLine;
if(!itemsMap.containsKey(item)){
itemsMap.put(item,0);
}
}else {
int quantity = Integer.parseInt(inputLine);
int currentQuantity = itemsMap.get(item);
itemsMap.put(item,currentQuantity + quantity);
}
inputLine = scanner.nextLine();
}
itemsMap.entrySet().forEach(entry ->{
System.out.printf("%s -> %d%n",entry.getKey(),entry.getValue());
});
}
}