Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. package Lesson10;
  2.  
  3. import java.util.HashMap;
  4. import java.util.HashSet;
  5. import java.util.Map;
  6. import java.util.Set;
  7.  
  8. public class Main {
  9.  
  10. public static void main(String[] args) {
  11. String stroka = "4, 2, 3, 4, 4, 5";
  12. int[] mas = {4, 4, 3, 4, 4, 4, 5};
  13. stroka = stroka.replace(",", "");
  14. System.out.println(stroka);
  15. Set<Integer> hashSet = new HashSet<Integer>();
  16. char[] strChar;
  17. strChar = stroka.toCharArray();
  18. for (int i = 0; i < mas.length; i++) {
  19. hashSet.add(mas[i]);
  20. }
  21. for (int i : hashSet) {
  22. System.out.print(i + " ");
  23. }
  24. System.out.println("\n---------------------------------------------");
  25. Map<Integer, Integer> hashMap = new HashMap<Integer, Integer>();
  26. Map<Integer, Integer> hashMapTemp = new HashMap<Integer, Integer>();
  27. for (int i = 0; i < mas.length; i++) {
  28. if (hashMap.containsKey(mas[i])) {
  29. hashMap.get(mas[i]);
  30. hashMap.put(mas[i],hashMap.get(mas[i]) + 1);
  31. System.out.println("Dobavka");
  32. } else {
  33.  
  34. hashMap.put(mas[i], 0);
  35. }
  36. }
  37.  
  38. for (int i : hashMap.keySet()) {
  39. System.out.print(i + " ");
  40. }
  41.  
  42. System.out.println();
  43. for (int i : hashMap.keySet()) {
  44. System.out.print(hashMap.get(i) + " ");
  45. }
  46.  
  47. System.out.println("\n---------------------------------------------");
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement