我需要输入成绩列表,并在输入字符时让代码停止。然后它会显示最高等级和最低等级。
我创建了一个while loop,但是当我运行代码时,它一直循环并且不会停止。
public class MaxMinGrades{
public static void main(String[] args){
double maxGrade = Double.MAX_VALUE;
double minGrade = Double.MIN_VALUE;
Scanner input = new Scanner(System.in);
System.out.println("Enter as many student grades as you like. Enter a character to stop.");
double grades = input.nextDouble();
while(input.hasNextDouble()) {
if (grades > maxGrade) {
maxGrade = grades;
}
if (grades < minGrade) {
minGrade = grades;
}
}
System.out.println("The highest grade is: " + maxGrade);
System.out.println("The lowest grade is: " + minGrade);
}
}
我会输入:50 66.85 73.5 78.9 77q。
输出将是: 最高等级是:78.9 最低等级是:50.0
杨__羊羊
狐的传说
侃侃无极
相关分类