[Nottingham] Introduction and Java Question

David Aldred david at familyaldred.org.uk
Sun Oct 19 10:19:10 UTC 2008

On Sunday 19 Oct 2008, Jason Liquorish wrote:
> I also have a quick question for the list to do with a college
> assignment for my programming module. I have been asked to write a
> program to read in a file of numbers separated by commas, then to work
> out the mean, median and mode and print the results. I got the mean and
> median sorted in a night but the mode has been a real headache for me,
> I just cannot figure it out in my head how to do it. I am not looking
> for someone to just post some code for me to use, I will not learn that
> way, I would like some tips/pointers/advice as to what I should think
> about and what methods I should use to work this out. I should also add
> with the mode, if two or more numbers occur the same amount of times
> then I have to print out all numbers that occur the most.

...so you need to count instances of numbers read from the list, then sort by 
the count.  The mode is the highest in the sort - if there's more than one 
highest count then you print both/all.

David Aldred

More information about the Nottingham mailing list