import java.util.Scanner;

public class Main {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
while (n-- >= 0) {
int fact=in.nextInt(),count=0;

I made this program for finding the trailing zero in a factorial. The program is running just fine on an ide but giving nzec runtime error on codechef. Help me!!

Okay i am sorry i don’t know syntax of java but still tried to debug your code, and while running your code on ideone i got these results,

Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:907)
	at java.util.Scanner.next(Scanner.java:1530)
	at java.util.Scanner.nextInt(Scanner.java:2160)
	at java.util.Scanner.nextInt(Scanner.java:2119)
	at Main.main(Main.java:8)

You may check the code here:

http://ideone.com/P0IjJs (i ran your code keeping lang as JAVA)


http://ideone.com/cfnufH ( keeping lang as JAVA 7)

hope this help you…

You have a problem in the while loop which checks for the number of test cases,

Say, there are 5 test cases, then your code checks for 6 test cases.

Hence your loop is checking all the test cases and one extra for which there is not input present to the scanner.nextInt() method and it is throwing " java.util.NoSuchElementException " . This is why a nzec (Non Zero Exit Code) is encountered by the judge.

"while(n-->=0)" to "while(n--> 0)".

1 Like