0

I have a problem to understand array 2D looping concept. This is my code :

int[][] matA = new int[2][3];
matA[0][0] = 2;
matA[0][2] = 3;
matA[1][1] = -4;

for (int i = 0; i < matA.length; i++){
    for (int j = 0; j < matA[0].length; j++){
        System.out.print("\t" + matA[i][j]);
    }

    System.out.println("");
}

I know that matA[0].length used for displaying what is second array or [3] contain, I just don't understand how [0] on metA[0].length can displaying the second array

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
Okem
  • 395
  • 1
  • 4
  • 12

1 Answers1

0

Try to do it

int[][] matA = new int[2][3];
matA[0][0] = 2;
matA[0][2] = 3;
matA[1][1] = -4;

for (int i = 0; i < matA.length; i++){
    for (int j = 0; j < matA[i].length; j++){
        System.out.print("\t" + matA[i][j]);
    }

    System.out.println("");
}
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
vmontanheiro
  • 1,009
  • 9
  • 12