DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2005

    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

  2. #2
    Join Date
    Mar 2005
    Sendling, MUC, .de

    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...?"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.