【问题标题】:Java class error Main.java:3: error:Java 类错误 Main.java:3: 错误:
【发布时间】:2017-08-08 03:54:23
【问题描述】:

我不断收到此错误消息 我检查了我的文件名,并且我的公共类与我的 .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 + "%");
 }
}

【问题讨论】:

标签: java class main


【解决方案1】:

您的文件名为 Main.java,您的类为 ClassGenderPercentages。 您可以将文件重命名为 ClassGenderPercentages.java (您从编译器收到的错误中已经说过)

【讨论】:

    猜你喜欢
    • 2021-02-21
    • 2021-05-27
    • 2014-01-21
    • 2015-08-29
    • 2021-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多