wormwood wormwood - 3 months ago 14
Java Question

NZEC error in SPOJ

Why am I getting runtime NZEC error in SPOJ when I paste this code?

package spoj.test;

import java.util.*;

public class Main {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int number = 0;
while (number != 42) {
try {
number = scanner.nextInt();
} catch (InputMismatchException exception) {
System.out.println("Error");
System.exit(0);
}
if (number != 42)
System.out.println(number);
}
}
}


I have tried every input I can think of and it runs fine. What could make this throw a non- zero error? Thanks in advance.

Answer

You can't place SPOJ submissions in a package, so remove the declaration:

package spoj.test;

The non-zero exit code probably comes from the JVM not being able to load the class to run it.

Comments