Mode......(yeah you think it would be simple)
So, we all know about the good old word MODE......well it has been tantalizing me for the past few days.
I enter the numbers from a text file into an array, not knowing how many numbers are in the text file, but i do know that the maximum for the array is 100. I then loop through entering each number into the array, and count how many numbers are entered.
Now using that array I call a method called findMode(), which must do the following i believe:
must loop through the array ending once i have gotten to the amount entered, with this loop i am meant to find the array, I can only use this one array, no making another, i can't use anything like a hashtable or hashmap. The mode must be found only using the one array already declared, once i loop through i should return the mode.
I know what i have to do, it is just i don't know how to put it down in words of Java
Thanks for any Help
MODE for breakfast
Sorry, I don't get what exactly are the requirements. So here's a suggestion for a definite restatement of your assignment. If incorrect, plz tell (otherwise too ).
- the numbers in question are all integers in the range [0,100]
- among how many numbers we are supposed to find the mode is not known at first but when it's up to actually finding it, we're presented an array containing the numbers and at this point the length of this array is known
- the actual work has to be done in a method with signature int findMode(int a)
- in that method we may only use local variables of type int and only, say, 5 of them or so (not 100, no arrays, no BigInteger,...)
- no API calls like Arrays.sort(...), System.arraycopy(...) or so are allowed
- we may loop through the array only once, ie for each 0<=i<=a.length a[i] may be called at most once. This implies that if we do want to read every element, then (the contents of) the array cannot be changed.
Right? If so, I doubt that it's even possible, yet I don't have a proof for that.
ps: just in case someone's interested in that other discussion on the mode: "I can't find the mode...?"
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL