Manuel Del Toro
Manuel Del Toro

Reputation: 17

groovy.lang.GroovyRuntimeException - Groovy error

I have been doing some test in Groovy. I have done this code and I and get this error

Caught: groovy.lang.GroovyRuntimeException: This script or class could not be run. It should either:


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);
}

}

Upvotes: 0

Views: 1581

Answers (1)

pczeus
pczeus

Reputation: 7867

The signature of your main method is incorrect (Need String... args).

Change it to:

public static void main(String... args) {

Upvotes: 2

Related Questions