I am trying to switch the rows and columns for a 2d array. For example:
[1,1,1]
[2,2,2]
[3,3,3]
goes to
[1,2,3]
[1,2,3]
[1,2,3]
However, my code returns the same 2d array as when it starts. Anyone know how to fix this?
Code:
public static int[][] invert(int[][] array) {
for(int j = 0; j < array.length; j++) {
for(int i = 0; i < array[j].length / 2; i++) {
int temp = array[j][i];
array[j][i] = array[j][array[j].length - i - 1];
array[j][array[j].length - i - 1] = temp;
}
}
return array;
}