Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What is wrong with the method for my int array?  RSS feed

 
Jose Castillo
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paul Clapham
Sheriff
Posts: 22493
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Carey Brown
Bartender
Posts: 2995
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!