gpt4 book ai didi

java - USACO 培训 – 文本提交给我一个错误 : "Error:_Main_method_not_found_in_class_test"

转载 作者:行者123 更新时间:2023-12-01 16:13:22 27 4
gpt4 key购买 nike

我正在处理 USACO 培训页面的第一个问题,它要求您提交一个简单的解决方案。虽然我的代码可以在 IDE 上编译,但 USACO 评分器给我一个错误,说找不到 main。

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

    ------ Data for Run 1 [length=4 bytes] ------
1 1
----------------------------

Your program printed data to stderr. Here is the data:
-------------------
Error:_Main_method_not_found_in_class_test,_please_define_the_main_method_as:
___public_static_void_main(String[]_args)
or_a_JavaFX_application_class_must_extend_javafx.application.Application
-------------------

我的代码:

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

class test
{
static class InputReader
{

BufferedReader reader;
StringTokenizer tokenizer;

public InputReader() throws FileNotFoundException{
reader = new BufferedReader(new FileReader("test.in"));
tokenizer=null;
}

String next() { //reads in the next String
while (tokenizer ==null || tokenizer.hasMoreTokens()){
try{
tokenizer= new StringTokenizer(reader.readLine());
}catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt(){ //reads in the next int
return Integer.parseInt(next());
}
public long nextLong(){ //reads in the next long
return Long.parseLong(next());
}
public double nextDouble(){ //reads in the next double
return Double.parseDouble(next());
}


public static void main (String [] args) throws IOException {

InputReader r= new InputReader();
PrintWriter pw= new PrintWriter(new BufferedWriter(new FileWriter("test.out")));

// your code here
int a = r.nextInt();
int b = r.nextInt();
pw.println(a+b);

pw.close();

}
}
}

最佳答案

我认为问题可能是您缺少代码顶部的标识注释。

正如您从 problem statement 中看到的那样,标题注释:

/*
ID: your_id_here
LANG: JAVA
TASK: test
*/

为必填项。

关于java - USACO 培训 – 文本提交给我一个错误 : "Error:_Main_method_not_found_in_class_test",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62472231/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com