Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. package by.academy;
  2.  
  3. import java.util.*;
  4.  
  5. public class Task4 {
  6. public static void main(String... args) {
  7. Map<String, Integer> catalog = new LinkedHashMap<String, Integer>(10);
  8. String product;
  9. Scanner sc = new Scanner(System.in);
  10. System.out.println("Add 10 products: ");
  11. for (int i = 0; i < 10; i++) {
  12. product = sc.nextLine();
  13. boolean b = catalog.containsKey(product);
  14. if (b == true) {
  15. catalog.put(product, catalog.get(product) + 1);
  16. } else {
  17. catalog.put(product, 1);
  18. }
  19. }
  20. sc.close();
  21. for (String key : catalog.keySet()) {
  22. System.out.println(key + ": " + catalog.get(key));
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement