This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

array subtraction  RSS feed

 
TIM SAN
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I'm trying to make a number list in which users picks a number from a list of 9 then the number is removed from the list how would i go about doing this?
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have a look at ArrayList. This will probably have all you need.
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As a matter of fact, this can be done in various ways, one of these ways is to use the ArrayList class.

Take a look at the Collections Framework.

Good luck ...
 
TIM SAN
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would this work
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by TIM SAN:
would this work

How could you write code to test this?
 
Srikanth Ramu
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can either construct a new int[] by adding all the elements except 8th element or as mentioned above you need to createan ArrayList by adding all the elements of "number" and then use "remove" method.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think the original problem is well defined. if this were my original array:

{1,2,3,4,5,6,7,8,9}

and the user enters a '3', what EXACTLY should the array look like? Are you removing the third element? are you removing the element with the index of 3? or are you removing elements that contain the value of '3' - and if so, do you do the first, the last, or all of them?

if you do want to remove the element, should you then collapse the remaining values? in other words should you have this:

{1,2,0,4,5,6,7,8,9}

or this:

{1,2,4,5,6,7,8,9}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!