Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. int[] arr = { 1, 9, 2, 7, 4, 9, 3, 8, 5, 6,10,9 };
  7. System.out.println(Arrays.toString(arr));
  8. System.out.println();
  9.  
  10. HashMap<Integer, Integer> hm = new HashMap<>();
  11.  
  12. for (int count : arr) {
  13. if (!hm.containsKey(count)) {
  14. hm.put(count, 1);
  15. } else {
  16. hm.put(count, hm.get(count) + 1);
  17. }
  18. }
  19.  
  20. Set<Map.Entry<Integer, Integer>> hms=hm.entrySet();
  21. for(Map.Entry<Integer, Integer> hmse:hms){
  22. System.out.println(hmse.getKey()+"\t"+"Meet "+hmse.getValue()+" time(s)");
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement