1. Member
Join Date
Jan 2013
Posts
22
Rep Power
0

## 2D Array Problem

Ok guys, I'm having a problem on how to mix this with aryNum with cars.

So here is my output :

As expected output is :

Here's ma code ::

Java Code:
```package SecYr;

public class multiDimensional {

public static void main(String[] args) {
String color[] = { "Red" , "Brown" , "Black" , "White" , "Gray" } ;
String cars[] = { "GM" , "FORD" , "TOYOTA" , "BMW" , "NISSAN" , "VOLVO" } ;
int[][] aryNum = { {10,7,12,10,4},
{18,11,15,17,10} ,
{12,10,9,5,12},
{16,6,13,8,3},
{10,7,12,6,4},
{9,4,7,12,11} } ;

for ( String element : color) {
System.out.print ("\t" + element ) ;
}
System.out.print ("\n") ;

for ( String car : cars){
System.out.print ("\n"+car);
}
System.out.print("\n");
int rows = 6;
int columns = 5;

int i, j;

for (i=0; i < rows ; i++) {

for (j=0; j < columns ; j++) {

System.out.print("\t[" + aryNum[ i ][ j ] + "] " );

}

System.out.println( "" );

}

}

}```

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,922
Rep Power
10

## Re: 2D Array Problem

Ok. You used nested for loops to print out the numbers. Place the print statement for the cars after the first of the nested for loops. And index it like an array using i.

Regards,
Jim

3. Member
Join Date
Jan 2013
Posts
22
Rep Power
0

## Re: 2D Array Problem

Originally Posted by jim829
Ok. You used nested for loops to print out the numbers. Place the print statement for the cars after the first of the nested for loops. And index it like an array using i.

Regards,
Jim
I got it now, it is just this statement :
Java Code:
```for ( String car : cars){
System.out.print ("\n"+car);
}
System.out.print("\n");```
create an another lining and doesn't connected to nested loop.

Sorry I'm noob.

Thanks and now its okay.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•