Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // first change ur hash map to look like this
- HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
- //then once your hash map has all the values calculated and shit, do this:
- // make ArrayList to store modes
- ArrayList<Integer> shit = new ArrayList<Integer>();
- //get the iterator for all the key-value pairs
- Iterator naga = map.entrySet().iterator();
- int max_freq = 0;
- while(naga.hasNext()){
- Map.Entry<Integer,Integer> weed = naga.next();
- int freq = weed.getValue();
- if(freq > max_freq){
- max_freq = freq;
- // clear shit array
- shit = new ArrayList<Integer>();
- shit.add(weed.getKey());
- }
- else if (freq == max_freq){
- shit.add(weed.getKey());
- }
- }
- //print shit array to see all the modes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement