TEST: Getting NZEC error in java

Hi,

I am using codechef for the first time. I am trying to run this simple code in Java but it
is giving an NZEC error everytime and I can’t figure out why :

public class Main{
 
 public static void main(String[] args) throws java.io.IOException {

  java.io.BufferedReader f = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
  int i = 0;
  i = Integer.parseInt(f.readLine().trim());

  while(i!=42)
   {
      System.out.println(i);
      i = Integer.parseInt(f.readLine().trim());
   }  
   f.close();
 }
}  

This the problem - http://www.codechef.com/problems/TEST
The problem just asks to read one or two digit integers and print them back until 42 is encountered. The code is running fine on my personal computer. Please help me out.

1 Like

I tried it and there is problem with f.close(). In fact I have no idea why this is a problem, but when I tried to comment this statement it’s ok (it gets AC).

2 Likes

Please help me this gives a RUNTIME ERROR according to code chef test.Please tell how to remove it
thanks in advance heres my code in java…

Errorcode:NZEC
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
private static int position=0;
private static ArrayList ints=new ArrayList();
public static void main(String args[]) throws Exception
{

    while(true){
    int input=new Scanner(System.in).nextInt();
    
    if(input!=42)    
    {ints.add(input);
     position++;
    }   
    else
    {
    for(int i=0;i<position;i++)
        {
        
            System.out.println(ints.get(i));
        }
     
    return;
    }
    
    }
    
}

}

Thanks a lot!! That fixed it.

solved the problem…was creating the scanner again and again…terms and conditions/FAQ’s of code chef helped…

1 Like

This does work!!! THank you!!!