首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >groovy.lang.GroovyRuntimeException - Groovy错误

groovy.lang.GroovyRuntimeException - Groovy错误
EN

Stack Overflow用户
提问于 2016-02-28 23:13:18
回答 1查看 1.2K关注 0票数 0

我在Groovy中做了一些测试。我已经完成了这段代码,并得到了这个错误

捕获: groovy.lang.GroovyRuntimeException:无法运行此脚本或类。它应要么:

  • 有个主要方法,
  • 做一个JUnit测试或者扩展GroovyTestCase,
  • 实现可运行的接口,
  • 或者与注册的脚本运行程序兼容。已知跑步者:无
代码语言:javascript
复制
class Prime {

public static def prime(int x){ 
    boolean result = true;
    int i, j, temp;
    temp = 0;

    if (x < 2){
        result = false;
    }else {
        for(i = 2; i < x && j == 0; i++){
            temp = x % i;
            if(temp == 0){
                result = false;
            }
        }
    }
    return result;
}

static void main() {

    long time_start, time_end, time_exe;
    int primes = 0;
    int N = (int) Math.pow(8, 5);

    time_start = System.currentTimeMillis();

    def fichero = new File("salida2.out")

    for (int i = 0; i <= N; i ++) {
      if (prime(i)  == true) {
        String line =  "" + i + " is prime.";
        fichero.append(line);

      }
    }

    time_end = System.currentTimeMillis();

    time_exe = time_end - time_start;

    println("Execution time: " + time_exe + "milliseconds");
    println("Prime Numbers Found: " + primes);
}

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-28 23:15:47

主方法的签名不正确(需要字符串.args)。

改为:

代码语言:javascript
复制
public static void main(String... args) {
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35689484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档