在USACO中,此编译器不断出现

时间:2016-10-03 01:13:17

标签: java

ride.java:8: class Ride is public, should be declared in a file named Ride.java
public class Ride {
       ^
1 error

这是我的代码

import java.util.*; 
import java.io.*;

public class Ride {

    static Scanner reader;
    static PrintWriter outFile;
    int num = 0;
    int total_c = 0;
    int total_g = 0;
    char [] comet = new char [6];
    char [] group = new char [6];

    public static void main (String [] args) throws Exception
    {
        reader = new Scanner(new File("ride.in"));
        outFile = new PrintWriter(new File("ride.out"));
        Ride r = new Ride();
        r.run();
    }

    public void run()
    {
        char in = '\0';
        int x = 0;
        while(reader.hasNext())
        {
            in = reader.next().charAt(0);
            if(x<6)
            {
                comet[x] = in;
            }
            else 
            {
                group[x-6] = in;
            }
            x++;
        } 

        for(int a = 0; a < 6; a++)
        {
            total_c *= (int)(comet[a]-64);
            total_g *= (int)(group[a]-64);
        }

        if(total_c%47 == total_g%47)
        {
            outFile.print("GO");
        }
        else
            outFile.print("STAY");
    }
}

我确实有Ride.java下的文件,但USACO无法编译该程序。

1 个答案:

答案 0 :(得分:0)

如果您声明具有不同文件名的单个类,则会发生这种情况。如需简单提醒:

  

Java文件名必须与公共类名相同。

@deco answer可以为您提供更多详细信息。