I created a method that reads a bunch of numbers from a file, takes the first two numbers to be the row and the column length of the array, then converts the rest of them into integers and places the integers into the two dimensional array:
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;
}
My question is how would I access the individual elements in my multidementional array filledArray
? As in, how would I print what's in filledArray[1][3]
or add filledArray[1][3]+filledArray[2][3]
in the main method?