Create the new array WHEN you know how large it needs to be. The new code I've described would replace this statement:
valueFound.length = count;
After the copy was made, valueFound could be...
Type: Posts; User: Norm
Create the new array WHEN you know how large it needs to be. The new code I've described would replace this statement:
valueFound.length = count;
After the copy was made, valueFound could be...
If you have an array with 10 slots with the first 6 elements containing data
and create a new array with 6 slots
and copy the first 6 slots from the first array to the second array, (See the Arrays...
I suggested that you create a NEW array of the desired size.
Then copy the elements from the old array to the new array. The Arrays class has a method to do that.
ArrayList is a java class. ...
Use an ArrayList to hold the data and there is no need to resize it.
See post #18
To change size: define a new array of the desired size and copy the contents of the old array to the new array.
What are you trying to do with this statement:
valueFound.length = count; // change the size of the array????
That value has the length of the array. You can NOT change the size of an array. You CAN define a new array of the desired size and copy the contents of the old array to the new array.
What was the size of the array where the error happened?
How did the index for that array get the value: 10?
The code changes the value of the for loop control variable: k inside the loop....
At line 58 the code used an index with value of 10 in an array that had less than 11 elements in it.
Check the code to see why the value of the index went past the end of the array.
Remember that...
Does the code do what you want now?
You have gone too far with the comments now. Several of them are redundant.
Put a few lines of comments before a major loop describing its purpose. Most of...
If those comments were in the code, it would make the code easier to understand.
Did you understand the pseudo code I posted for searching a list for the smallest value?
What are the two loops for? Is this code only for finding the smallest value or is there other stuff mixed in with it?
BTW That is what comments are for > To describe what the code is supposed to...
Save them in a list or array.
Search the list for the smallest.
Do you have a question or problem?
An array would work, but it has maintenance problems. An ArrayList is much easier to use.