I came across this computer science problem and it wasn't working out the way I was writing it down. This is the code:
int[][]grid = {{1,2,3,4},{5,6,7},{8,9},{10}};
for(int i = 0; i < grid.length; i++)
for(int j = 0; j < grid[i].length; j++)
grid[j][i] = grid[i][j];
System.out.println(Arrays.toString(grid[1]));
It should change grid[0] to {1, 5, 8, 10} but instead it does nothing to it. Why does it skip over that one? Shouldn't i start out as 0 so the second for loop should start with grid[0][0] = grid[0][0] then grid[1][0] = grid[0][1]?
grid[i][j] = grid[j][i];