2
.txtファイルからインポートされた二重配列を逆にしようとしています。しかし、プログラムを実行すると、配列の最初の半分だけが逆転し、配列の残りの半分は0が出力されます。助言がありますか?ここに私のコードは次のとおりです。2次元配列を逆転させるのに問題がありますか?
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){
}
}
}