我正在开展一个项目,该项目涉及输入多个人的姓名和标记,然后计算平均值并输出高于平均值的人的姓名和标记。
public static void main(String[] args) {
Scanner kybd = new Scanner(System.in);
int sum = 0;
double average = 0;
System.out.println("Enter How many students");
int numberOfStudents = kybd.nextInt();
if (numberOfStudents <= 0) {
System.out.println("No Students");
}
if (numberOfStudents > 0) {
String[] studentNames = new String[numberOfStudents];
int[] marks = new int[numberOfStudents];
for (int i = 0; i < numberOfStudents; i++) {
System.out.println("Please Enter Name");
studentNames[i] = kybd.nextLine();
kybd.next();
System.out.println("Please Enter Marks");
marks[i] = kybd.nextInt();
sum += marks[i];
average = (double) sum / numberOfStudents;
}
System.out.println("average" + average);
System.out.print("Scores Above the Average: ");
for (int i = 0; i < numberOfStudents; i++) {
if (marks[i] > average) {
System.out.print(marks[i] + ", " + studentNames[i] + ", ");
} else {
}
}
}
}
我得到的问题是高于平均输出的标记,但名称不是