wood burning stoves*
The moose likes Beginning Java and the fly likes Code for user input for multi arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Code for user input for multi arrays

anise hollingshead
Greenhorn

Joined: Sep 07, 2006
Posts: 4
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

Joined: Aug 31, 2006
Posts: 226
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

Joined: Aug 31, 2004
Posts: 11343

Please continue this discussion in its original thread. (And please don't post duplicates. )


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Code for user input for multi arrays