• Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating one element in a multi-dimensional string array.  RSS feed

 
Darren Estcourt
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a two dimensional string array, one element holds letters (a football team name) and another holds a five digit number (stadium capacity). I would like to know how I can update the second element (which holds a number), when the user has added more "stadium seats". My 2D Array is called "club" (see parameter for the method). I am a newb, so I don't know whether, what I'm trying to do, is even possible. I have googled this numerous times and cannot find out whether this is possible. I have tried to indent this, but my browser is playing up, so apologies if the formatting is not ok.

My method is shown below.
 
Darren Estcourt
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I sorted out the indentation in my IDE, but when pasting it into this window, the indentation isn't copied across. I would be most grateful, if anyone could just give me a pointer in the right direction. I don't know whether what I'm trying to do, is even possible. Thanks
 
Carey Brown
Saloon Keeper
Posts: 3324
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What IDE are you using?

I'd add a constant to eliminate a magic number. Also, only ever create one scanner for System.in and then share it.

You have a for() loop to find a stadium. This is not necessary, you can go directly to the array element.
Replace

with

I'm not sure  you are using arrays correctly. It seems that you have
If you never use any other index other than one, why not just
to hold the capacity
 
Dave Tolls
Ranch Foreman
Posts: 3065
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The formatting issue is because you are using a mixture of tabs and spaces for you indenting.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darren Estcourt wrote:I have a two dimensional string array, one element holds letters (a football team name) and another holds a five digit number (stadium capacity). I would like to know how I can update the second element (which holds a number), when the user has added more "stadium seats".

I'm not sure a String array is the data structure you need.  What about a Map?
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darren Estcourt wrote:. . . . My 2D Array . . .
Despite what people may tell you, that isn't a 2D array. that is an array of arrays, which is different. Did you get the September CodeRanch Journal? I thnk there was a link to a discussion about arrays of arrays there. This is it; make sure you have a very large cup of coffee to drink while reading it.
 
Darren Estcourt
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks all, in particular to Carey, who highlighted two areas, where my code could be improved upon. I was using the "codeanywhere.com" IDE, apologies for the indentation.

I concluded that my design was entirely wrong, a "2D array" as I refer to it (perhaps wrongly!) should not really be a string, which has one set of elements with numeric data. I split them eventually into single dimension arrays and this has simplified things, and I have sorted this method out.

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!