ファイルから一連の数値を読み取り、最初の2つの数値を配列の行と列の長さにして、残りを整数に変換し、整数を2次元配列に配置するメソッドを作成しました。
public static int[][] fillArray(String myFile){
//uses another class to create a text field
TextFileInput in = new TextFileInput(myFile);
int[][] filledArray;
//uses a method in class TextInputFile to read a line then go to the next line
String line = in.readLine();
//int i=0;
int row, col;
row = Integer.parseInt(line);
line = in.readLine();
col = Integer.parseInt(line);
filledArray = new int[row][col];
for(int i=0; i<row; i++){
for (int j=0; j<col; j++){
line = in.readLine();
filledArray[i][j] = Integer.parseInt(line);
}
}
return filledArray;
}
私の質問は、多次元配列の個々の要素にどのようにアクセスするfilledArray
かです。のように、メインメソッドに何が含まれているかを印刷filledArray[1][3]
または追加するにはどうすればよいですか?filledArray[1][3]+filledArray[2][3]