Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lesson10;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Map;
- import java.util.Set;
- public class Main {
- public static void main(String[] args) {
- String stroka = "4, 2, 3, 4, 4, 5";
- int[] mas = {4, 4, 3, 4, 4, 4, 5};
- stroka = stroka.replace(",", "");
- System.out.println(stroka);
- Set<Integer> hashSet = new HashSet<Integer>();
- char[] strChar;
- strChar = stroka.toCharArray();
- for (int i = 0; i < mas.length; i++) {
- hashSet.add(mas[i]);
- }
- for (int i : hashSet) {
- System.out.print(i + " ");
- }
- System.out.println("\n---------------------------------------------");
- Map<Integer, Integer> hashMap = new HashMap<Integer, Integer>();
- Map<Integer, Integer> hashMapTemp = new HashMap<Integer, Integer>();
- for (int i = 0; i < mas.length; i++) {
- if (hashMap.containsKey(mas[i])) {
- hashMap.get(mas[i]);
- hashMap.put(mas[i],hashMap.get(mas[i]) + 1);
- System.out.println("Dobavka");
- } else {
- hashMap.put(mas[i], 0);
- }
- }
- for (int i : hashMap.keySet()) {
- System.out.print(i + " ");
- }
- System.out.println();
- for (int i : hashMap.keySet()) {
- System.out.print(hashMap.get(i) + " ");
- }
- System.out.println("\n---------------------------------------------");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement