Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
  1. #21
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Help with padding arrays

    More efficient than what? For each score entered you are adding another iteration over the array to find where to place the new score which has a larger Big O notation (n) plus moving all smaller scores Big O (n/2) than simply adding the new score to the end of the array Big O (1).

  2. #22
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,377
    Rep Power
    5

    Default Re: Help with padding arrays

    More efficient than sorting. But 1) I was trying to limit it to an array of size 6 since the actual number of inputs is unknown, and 2) early in the post you said you didn't even need an array. Since I am eager to learn, please explain to me how you might approach it with no upward limit of input and not using arrays.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #23
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Help with padding arrays

    Quote Originally Posted by jim829 View Post
    early in the post you said you didn't even need an array.
    That was before I realised that one of the requirements was to only sum the top 6 scores and drop the rest. If this was not a requirement you would simply read in the score and add it to a sum which does not need an array.

  4. #24
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,377
    Rep Power
    5

    Default Re: Help with padding arrays

    I agree with that. But I am curious as to how you would approach it since arrays don't grow dynamically. Perhaps I am missing something but it seems to me you have to scan the array for the next value to be replaced.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #25
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Help with padding arrays

    Maybe the full assignment provides details such as "a maximum of 10 scores will be entered but user can enter less than 10 and indicate the end of input with -1". In a previous post by the OP I did notice they mentioned the -1 flag.

    Otherwise you could create a larger array when the original becomes full and copy all values across using System.arraycopy(). This of course is messy and adds extra work.

  6. #26
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,377
    Rep Power
    5

    Default Re: Help with padding arrays

    I agree. I got carried away and was approaching the problem from a situation where there was no known maximum. But for a real situation with test scores, a small number of tests would certainly be known. I enjoyed the dialog!

    Regards,
    Jim
    Last edited by jim829; 04-04-2013 at 05:25 AM.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  7. #27
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Help with padding arrays

    If this were a real application and not an "intro to java" assignment then a List would be the preferred option. Then the unknown number of scores becomes a moot point.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Vertical padding problem
    By phil128 in forum AWT / Swing
    Replies: 1
    Last Post: 01-30-2011, 09:13 PM
  2. BAd Padding exception
    By Bverly in forum Advanced Java
    Replies: 1
    Last Post: 09-26-2010, 09:48 PM
  3. Padding Problem
    By Srikar in forum Advanced Java
    Replies: 1
    Last Post: 08-20-2010, 08:39 PM
  4. Single Component Padding
    By subb in forum AWT / Swing
    Replies: 2
    Last Post: 03-28-2009, 07:09 PM
  5. padding informaiton for PKCS#5
    By nanaji in forum Advanced Java
    Replies: 3
    Last Post: 07-31-2008, 05:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •