What is the problem with this code(Java)

import java.util.Scanner;

public class Main

{

public static void main(String[]args){

Scanner kb=new Scanner(System.in);

int n=0;

while(n!=42)

{System.out.print("");

int a=kb.nextInt();

n=a;

if(n!=42)

{System.out.println(n);}}

System.exit(1);}}

when I submit it I get a NZEC runtime error
please help!

Try using return instead of System.exit(). My guess is that exit value 1 indicates some kind of error is Codechef’s environment.

Don’t Use Public class :stuck_out_tongue: and try now ??

The public class is obviously necessary.
Some guidelines given here: http://www.codechef.com/wiki/sample-solutions#Java
. I was having the same problem. I tried using the InputStreamReader instead of the Scanner and it worked for me. InputStreamReader is also much faster than Scanner for large inputs, however less convenient.
Don’t really know if and why Scanner is a problem, let me know if you find out.

yup, return fixed it .thanks for the help everyone.