java在反转二维数组时遇到问题?
我正在尝试反转从导入的双数组。txt文件。但是,当我运行程序时,它只反转数组的前半部分,而数组的另一半则打印出0。有什么建议吗?这是我的密码:
package arrayreverse;
import java.util.Scanner;
import java.io.*;
public class ArrayReverse {
public static void main(String[] args) throws IOException {
try{
File abc = new File ("filelocation");
Scanner reader = new Scanner(abc);
int [][] a = new int[5][10];
int [][] b = new int [5][10];
for (int row = a.length - 1; row >= 0; row--){
for (int col = a[row].length - 1; col >= 0; col--){
a[row][col] = reader.nextInt();
b[row][col] = a[row][col];
a[row][col] = b[4-row][9-col];
System.out.print(a[row][col]+" ");
}
System.out.println();
}
}
catch (IOException i){
}
}
}
# 1 楼答案
试试这个
}
# 2 楼答案
请尝试以下操作:
循环完成时
a
和b
应该彼此相反