我一直收到此错误消息我已检查过我的文件名,而我的公共类与我的.java文件相同。除了检查我不知道去哪里。
Main.java:3: error: class ClassGenderPercentages is public, should be declared in a file named ClassGenderPercentages.java
public class ClassGenderPercentages
^
这是我的代码
import java.util.Scanner;
public class ClassGenderPercentages
{
public static void main (String args[])
{
Scanner keyboard = new Scanner(System.in);
int maleStudents, femaleStudents;
int totalStudents;
double maleStudentPercentage, femaleStudentPercentage;
maleStudents = keyboard.nextInt();
System.out.println("Enter number of male registered:" + maleStudents);
femaleStudents = keyboard.nextInt();
System.out.println("Enter number of female registered:" + femaleStudents);
totalStudents = (int) (maleStudents + femaleStudents);
maleStudentPercentage = ((100 * maleStudents) / totalStudents);
femaleStudentPercentage = ((100 * femaleStudents) / totalStudents);
System.out.println("The percentage of males registered is: " + maleStudentPercentage + "%");
System.out.println("The percentage of females registed is: " + femaleStudentPercentage + "%");
}
}
答案 0 :(得分:0)
您的文件名为Main.java,您的类为ClassGenderPercentages。 您可以将文件重命名为ClassGenderPercentages.java (已在编译器收到的错误中说过)