• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

What is wrong with the method for my int array?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 27368
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Saloon Keeper
Posts: 9558
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
That new kid is a freak. Show him this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic