my first program in java @codechef shows run time error?

here is the code:


 public class Main{
public static void main(String args[])
{
  int n;
  boolean fact=true;
  while(fact)
  {
  n=Integer.parseInt(System.console().readLine());
  if(n==42)
  {
  fact=false;
  break;
  }
  System.out.println(n);
  }}}

System.console().readLine() is probably causing Runtime Error. Use Scanner or BufferedReader

It Depends On the Environment…
System.console()… returns null in an IDE…
Try Using Scanner…

//