编写一个代码,从标准输入逐行读取学生成绩列表,直到没有更多行要读取或遇到空行。如何在Java中看到空行时断开while循环?
但是,我无法退出循环。我试着写 Scanner input = new Scanner(input.hasNext());
和别人分手,但它不工作
public class NumInput {
public static void main(String [] args) {
float min = Float.MAX_VALUE;
float max = Float.MIN_VALUE;
float total=0;
int count=0;
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
float val = input.nextFloat();
if (val < min) {
min = val;
}
if (val > max) {
max = val;
}
count++;
total += val ;
}
float average = (float) total/count;
System.out.println("min: " + min);
System.out.println("max: " + max);
System.out.println("The Average value is: " + average);
}
}
执行该操作时会发生什么? –
Works [here](http://ideone.com/eNuYJd) – sam
也许这个链接可以帮助:http://stackoverflow.com/questions/16206813/how-to-terminate-scanner-when-input-is-complete –