Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
    Bookmark Topic Watch Topic
  • New Topic

Code for user input for multi arrays

 
anise hollingshead
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,

I'm still having problems coding for a multi dimensional array with user input.

I have this code for the input:
for(int i = 0; i < coffeeArray2.length; i ++)
{
for(int j = 0; j < coffeeArray2[i].length; j ++)
System.out.print("Enter number of lbs of coffee for the first aisle:");
coffeeArray2[i][j] = myInput.nextInt();

But this is only getting me one column of numbers.

How do you get input for all the boxes in a 5x2 array?

Thanks!
Anise
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Report post to moderator
That code fragment looks okay. Perhaps your problem is defining the array or the code you are using to go through the array to determine the values you have.

System.out.print("Enter number of lbs of coffee for the first aisle:");

Though I'd guess i is probably the aisle so this should be (the " + i + " aisle).
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please continue this discussion in its original thread. (And please don't post duplicates. )
 
    Bookmark Topic Watch Topic
  • New Topic