我正在学习 Java 入门课程,并且在从用户输入中提取数据并使用它根据用户输入量创建一组成绩时遇到问题。然后我假设从最高到最低组织该组数据并将其平均。到目前为止,这是我的代码
//import Scanner
import java.util.Scanner;
public class Looper {
public static void main(String[] args) {
//introduce integers
int highest = 0;
int lowest = 0;
int count = 0;
int grade = (int) (Math.random() * 100);
int student;
int total = 0;
double average = 0;
//introduce Scanner
Scanner input = new Scanner(System.in);
//printout number of students
System.out.println("Enter number of students");
student = input.nextInt();
//narrow amount of students
if (student <= 10) {
System.out.println("Enter the grades of the students");
}
else if (student >= 11) {
System.out.println("Too many Students");
}
//close off 0
while (student != 0) {
System.out.println("Didn't enter students");
}
grade = input.nextInt();
//connect student and grade
for (grade = 0; grade <= 100; grade++) {
student = grade;
if (grade > 100) {
System.out.println("Must be between 0 and 100")
} if (grade <= highest) {
grade++;
}
}
for (grade = 0; grade >= 0; grade++) {
student = grade;
if (grade < -1) {
System.out.println(" Must be between 0 and 100");
}
else if (grade >= lowest) {
grade++;
}
// form total and average
total = total + grade;
grade++;
{
average = (double) total / grade;
//printout highest, lowest, and average
System.out.println("The highest is" + highest + "\n The lowest is" + lowest + "The average is\n" + average);
}
}
}
}