【发布时间】:2013-02-25 02:00:43
【问题描述】:
我创建了一个从文件中读取一堆数字的方法,将前两个数字作为数组的行和列长度,然后将其余的数字转换为整数并将整数放入二维数组:
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] 中的内容或在 main 方法中添加 filledArray[1][3]+filledArray[2][3]?
【问题讨论】:
-
哦不,那我该如何结束这个问题呢?
标签: java arrays methods multidimensional-array return