# 2D Array Problem

• 09-07-2013, 05:30 PM
Aries.
2D Array Problem
Ok guys, I'm having a problem on how to mix this with aryNum with cars.

So here is my output :

http://i.imgur.com/EUWTWwq.png

As expected output is :

http://i.imgur.com/W0EqIuC.png

Here's ma code ::

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( "" );                 }                                         } }```

Thanks for the advance tips.
• 09-07-2013, 05:52 PM
jim829
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
• 09-07-2013, 06:02 PM
Aries.
Re: 2D Array Problem
Quote:

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 :
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.