• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help on array question?  RSS feed

 
Miles Davis
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following question as it appears in its entirety:

Complete this method in the NumberList class that inserts the given value at the first location among the values stored in itsItem[0] through itsItem[itsSize-1].



I cannot tell whether this is a terribly formulated question or whether I am missing something. First of all, I'm not really sure what the question is asking me to do, but since I see that itsSize++, it's possible that it wants me to shift all of the entries in the array to the right so that given can be inserted into itsItem[0]. This would be itsItem[k - 1] = itsItem[k]. However, this would throw an index out of bounds exception. Also, I am not sure how itsSize would increase at all, since the length of a vanilla array in Java cannot change. What should I do?
 
Ashley Bye
Ranch Hand
Posts: 140
2
Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume itsSize is set elsewhere and is an accurate representation of the size of itsItem[]. Do you have to solve it in one line as the question seems to indicate? If so, I don't see how that is possible. If not, have you considered a temporary array?
 
Miles Davis
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashley Bye wrote:I assume itsSize is set elsewhere and is an accurate representation of the size of itsItem[]. Do you have to solve it in one line as the question seems to indicate? If so, I don't see how that is possible. If not, have you considered a temporary array?


Yes, it must be solved in one line...
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have the correct solution and the last element just goes away.
 
Miles Davis
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I think you have the correct solution and the last element just goes away.


Alright, I don't see what else I could possibly put. Let's hope for the best.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!