Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- int[] arr = { 1, 9, 2, 7, 4, 9, 3, 8, 5, 6,10,9 };
- System.out.println(Arrays.toString(arr));
- System.out.println();
- HashMap<Integer, Integer> hm = new HashMap<>();
- for (int count : arr) {
- if (!hm.containsKey(count)) {
- hm.put(count, 1);
- } else {
- hm.put(count, hm.get(count) + 1);
- }
- }
- Set<Map.Entry<Integer, Integer>> hms=hm.entrySet();
- for(Map.Entry<Integer, Integer> hmse:hms){
- System.out.println(hmse.getKey()+"\t"+"Meet "+hmse.getValue()+" time(s)");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement