Forums Register Login

What is wrong with the method for my int array?

+Pie Number of slices to send: Send
Hey all,

I am tasked with not using any array methods aside from .length, and not to use ArrayList. Essentially, I am trying to add another int to the end of the array. If the array has a spot (i.e, a 0), it replaces that spot. If there is no free spots (i.e, no 0's) we double the size of the array, add the number, and return the same array. here's what I have:



and my GetCurrentSize code:


I think my issue lies with properly copying the temporary array to the permanent array (list). Any insight?
+Pie Number of slices to send: Send
Well, I wouldn't do it the way you're doing it. But let's go back a bit... you said "my issue" but I don't see where you describe any kind of problem. Did I miss something?
+Pie Number of slices to send: Send
Some style comments
Java has a not-equals operator for ints. Instead of

use

A variable name of 'list' in your case is misleading. It is an array, not a list. A name of 'array' would be more appropriate.
Rather than computing this size over and over, a better approach would be to have a member variable that keeps track of the size as you add and delete values.
Remember to always leap before you look. But always take the time to smell the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 350 times.
Similar Threads
More Array sorting trouble
Help
Timing Performance of a Sequential Search
Problem with bubbelsorting.
error
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:43:31.