Iterate through 2 dimensional array

前端 未结 5 1927
心在旅途
心在旅途 2020-12-10 13:30

I have a \"connect four board\" which I simulate with a 2d array (array[x][y] x=x coordinate, y = y coordinate). I have to use \"System.out.println\", so I have to iterate

5条回答
  •  再見小時候
    2020-12-10 14:05

    Just invert the indexes' order like this:

    for (int j = 0; j

    because all rows has same amount of columns you can use this condition j < array[0].lengt in first for condition due to the fact you are iterating over a matrix

提交回复
热议问题