I was tasked with reading a data.txt file using the scanner import. The data.txt file looks like this:
1 2 3 4 5 6 7 8 9 Q
I need to read and find the average of these numbers, but stop when I get to something that is not an integer.
This is the code that I have so far.
public static double fileAverage(String filename) throws FileNotFoundException {
Scanner input = new Scanner(System.in);
String i = input.nextLine();
while (i.hasNext);
return fileAverage(i); // dummy return value. You must return the average here.
} // end of method fileAverage
As you can see I did not get very far and I cannot figure this out. Thank you for your help.