You are not logged in. Please login at www.codechef.com to post your questions!

×

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!

asked 08 May '15, 13:39

harsh2808's gravatar image

2★harsh2808
31
accept rate: 0%

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

(08 May '15, 14:12) junior944★

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

(09 May '15, 13:26) harsh28082★

Don't Use Public class :P and try now ??

link

answered 08 May '15, 15:00

saajan's gravatar image

3★saajan
3362313
accept rate: 3%

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.

link
This answer is marked "community wiki".

answered 08 May '15, 16:42

yousuf_031991's gravatar image

2★yousuf_031991
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,096
×180

question asked: 08 May '15, 13:39

question was seen: 554 times

last updated: 09 May '15, 13:26