Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package by.academy;
- import java.util.*;
- public class Task4 {
- public static void main(String... args) {
- Map<String, Integer> catalog = new LinkedHashMap<String, Integer>(10);
- String product;
- Scanner sc = new Scanner(System.in);
- System.out.println("Add 10 products: ");
- for (int i = 0; i < 10; i++) {
- product = sc.nextLine();
- boolean b = catalog.containsKey(product);
- if (b == true) {
- catalog.put(product, catalog.get(product) + 1);
- } else {
- catalog.put(product, 1);
- }
- }
- sc.close();
- for (String key : catalog.keySet()) {
- System.out.println(key + ": " + catalog.get(key));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement