Storing data into a 2-dimensional array from an infile
I have a fairly simple issue that's been driving me crazy. Below is a method which is supposed to read an infile and store the data into a 2d array.
I keep getting compiler errors for the "inFile.next();" lines. Is there a special syntax to 开发者_Go百科use with storing inFiles into arrays? Or is it something else?
Below is my method:
// reads and stores data in the array
public static void getData(double t[][],int m) {
Scanner keyboard = new Scanner(System.in);
for (int i = 0; i < m; i++) {
t[i][0] = inFile.next();
t[i][1] = inFile.next();
} // end for
} // end function getData
replace inFile.next()
with keyboard.nextDouble()
Assuming that inFile is an instance of java.util.Scanner, you probably want inFile.nextDouble() here. inFile.next() returns a String.
精彩评论