如何使代码工作 - USACO培训第一任务

时间:2014-09-05 16:00:53

标签: java

我在USACO培训页面遇到第一个问题时遇到了问题。

任务是从text.in文件中请求两个字符串,将字符串转换为字母的乘积(其中a = 1,b = 2,z = 26),然后查看余数数字/ 47彼此相等(如果是,打印" GO"如果没有,打印"保持")。

它在我的计算机上运行良好,但是当我发送它时,它会显示:

> Run 1: Execution error: Your program exited with exit status `1'. 

    ------ Data for Run 1 [length=14 bytes] ------
    COMETQ 
    HVNGAT 
    ----------------------------

      Your program printed data to stderr.  Here is the data:
      -------------------
      Exception_in_thread_"main"_java.lang.NoClassDefFoundError:_ride
      Caused_by:_java.lang.ClassNotFoundException:_ride
        at_java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at_java.security.AccessController.doPrivileged(Native_Method)
        at_java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at_java.lang.ClassLoader.loadClass(ClassLoader.java:303)
        at_sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at_java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at_java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
      Could_not_find_the_main_class:_ride.__Program_will_exit.
      -------------------

现在这是我的代码:

/*
  ID:swagato1
  LANG:JAVA
  PROG:ride 
*/
import java.io.*;
class Ride{
    public void calculate() throws IOException{
       BufferedReader in=new BufferedReader(new FileReader("ride.in"));
       PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("ride.out")));
       String c=in.readLine();
       String g=in.readLine();
    int a=1,b=1;
    for(int i=0;i<c.length();i++)
        a*=((int)c.charAt(i))-64;
    for(int i=0;i<g.length();i++)
        b*=((int)g.charAt(i))-64;
    if ((a%47)==(b%47))
        out.println("GO");
    else
        out.println("STAY");
    out.close();
    System.exit(0);
}
public static void main(String args[]){
    try{new Ride().calculate();}
    catch(Exception e){
    }
}        
}

2 个答案:

答案 0 :(得分:1)

上课public

public class Ride{

   ...

}

答案 1 :(得分:0)

类名必须与任务名称完全相同。在这种情况下,它应该是ride而不是Ride。制作课程public无济于事。