尝试编译它后,始终出现错误“错误:找不到或加载主类GradesAverage”。 谁能帮助我了解这段代码出了什么问题?
package javaexercises.arrays;
import java.util.Scanner;
public class GradesAverage {
private final int LOWEST_GRADE = 0;
private final int HIGHEST_GRADE = 100;
// student's grades
private int[] grades;
private Scanner in;
/**
* Enter program's point.
*
* @param args
*/
public static void main(String[] args)
{
GradesAverage aGradesAverage = new GradesAverage();
aGradesAverage.in = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int numStudents = aGradesAverage.in.nextInt();
aGradesAverage.run(numStudents);
}
/**
* Run program.
*
* @param numStudents
*/
private void run(int numStudents)
{
if (numStudents <= 0) {
System.out.println("Invalid number of students.");
return;
}
grades = new int[numStudents];
double sum = 0;
int i = 0;
while (i < numStudents)
{
System.out.printf("Enter the grade for student %1$d: ", (i+1));
int grade = in.nextInt();
// chek if grade is between 0 and 100
if ((grade >= LOWEST_GRADE) && (grade <= HIGHEST_GRADE)) {
grades[i] = grade;
sum += grade;
i++;
continue;
}
System.out.println("Invalid grade, try again...");
}
System.out.printf("The average is %1$.2f\n", (sum / numStudents));
}
}
答案 0 :(得分:3)
一些在线编译器处理得不好。
注释此行
package javaexercises.arrays;
应该可以。