我觉得我的脑海中出现了这个问题,因为行和列很容易混淆。有人可以帮我看看我哪里出错了。
public static void switchRows( int[][] anArray ){
int num = 1;
for(int i = 0; anArray.length > i; i++){
for(int j = 0; anArray[i].length > j; j++){
int[][] temp = new int[anArray.length][anArray[i].length];
temp[i] = anArray[i];
anArray[i] = anArray[anArray.length - num];
anArray[anArray.length - num] = temp[i];
}
num++;
}
}
public static void switchColumns( char[][] anArray ){
int col = 1;
for(int i = 0; anArray.length > i; i++){
for(int j = 0; anArray[i].length > j; j++){
char[][] temp = new char[anArray.length][anArray[i].length];
temp[j] = anArray[j];
anArray[j] = anArray[anArray[i].length - col];
anArray[anArray[i].length - col] = temp[j];
}
col++;
}
}