0
Can anybody help me with the code of finding the mode of some datas?
4 Answers
+ 5
Share your try first
+ 1
Thanks
0
I don't have any idea of how to write that codeđ
0
Ok let's design your program together.
If I understand correctly, you have a series of numbers, and you want to find the most common number that appears the most times in the series. (this is 'mode').
So one simple algorithm could be this.
1. Your numbers are in an array or list
2. you create an empty HashMap
3. Iterate over the array and populate the hashmap in a way that the numbers are keys, and every time you iterate a number you increase the associated value in hashmap
4. Finally iterate through the hashmap to find the item with the largest value - that key is your solution