我正在创建一个程序,让用户输入 5 个介于 0-100 之间的值并将它们存储在一个数组中,以便可以打印最高值。问题是程序要求用户输入 5 个值后,它不会输出任何内容。
import java.util.ArrayList;
import java.util.Scanner;
public class HighestGrade {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
ArrayList<Integer> scores = new ArrayList<Integer>();
int greatest = -1;
for (int i=0; i<5; i++) {
System.out.print("Enter a grade (between 0 and 100): ");
scan.nextInt();
}
while (scores.size()<5) {
int input = scan.nextInt();
if (input <= 100 && input >= 00) {
scores.add(input);
if(input >= greatest)
greatest = input;
}
else{
System.out.println("Error: Make sure the grade is between 0 and 100!\nEnter a new grade!");
}
}
System.out.println("\nHighest grade: "+greatest);
}
}
叮当猫咪
Qyouu
一只名叫tom的猫
哔哔one
相关分类