I am looking for a way to traverse a 2d n by m int array (int[col][row]) first row by row (simple part) and then column by column, in Java. Here is the code for doing row by row, is there a way to do col by col?
for(int i = 0; i < display.length; i++){
            for (int j = 0; j < display[i].length; j++){
                if (display[i][j] == 1)
                    display[i][j] = w++;
                else w = 0;
            }
        }
                Since you used a two dimensional array as a matrix, we can assume that the length of each row is the same throughout the matrix (i.e. number of columns of each row is the same).
//So, you can treat display[0].length as the number of columns.
for(int col=0; col<display[0].length; col++)
{
   for(int row=0; row<display.length; row++)
   {
      //your code to access display[row][col]
   }
}
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With