Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java类错误Main.Java:3:error:_Java_Class_Main - Fatal编程技术网

Java类错误Main.Java:3:error:

Java类错误Main.Java:3:error:,java,class,main,Java,Class,Main,我一直收到这个错误消息,我已经检查了我的文件名,我的公共类与我的.java文件相同。除了检查我不知道去哪里 Main.java:3: error: class ClassGenderPercentages is public, should be declared in a file named ClassGenderPercentages.java public class ClassGenderPercentages ^ 这是我的密码 import java.util.Scan

我一直收到这个错误消息,我已经检查了我的文件名,我的公共类与我的.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 + "%");
 }
}

您的文件名为Main.java,您的类ClassGenderPentages。 您可以将文件重命名为classgenderpentages.java
(您从编译器收到的错误中已经提到了这一点)

错误的可能副本明确指出,文件名应为classgenderpentages.java,而您的文件名为Main.java