Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. // first change ur hash map to look like this
  2. HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
  3.  
  4. //then once your hash map has all the values calculated and shit, do this:
  5.  
  6. // make ArrayList to store modes
  7. ArrayList<Integer> shit = new ArrayList<Integer>();
  8.  
  9. //get the iterator for all the key-value pairs
  10. Iterator naga = map.entrySet().iterator();
  11.  
  12. int max_freq = 0;
  13.  
  14. while(naga.hasNext()){
  15. Map.Entry<Integer,Integer> weed = naga.next();
  16. int freq = weed.getValue();
  17. if(freq > max_freq){
  18. max_freq = freq;
  19. // clear shit array
  20. shit = new ArrayList<Integer>();
  21. shit.add(weed.getKey());
  22. }
  23. else if (freq == max_freq){
  24. shit.add(weed.getKey());
  25. }
  26. }
  27.  
  28. //print shit array to see all the modes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement