【发布时间】:2019-11-20 00:38:45
【问题描述】:
我的任务是使用扫描仪导入读取 data.txt 文件。 data.txt 文件如下所示:
1 2 3 4 5 6 7 8 9 问
我需要阅读并找到这些数字的平均值,但是当我得到一个不是整数的东西时就停下来。
这是我目前的代码。
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
如您所见,我没有走多远,我无法弄清楚这一点。感谢您的帮助。
【问题讨论】:
标签: java file java.util.scanner average throws