×

# How to get rid of getting NZEC error while submitting solution in java?

 1 4 To all who are geting NZEC, try using this format in java: import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { try{ //Your Solve }catch(Exception e){ return; } } }  asked 05 Aug '13, 14:28 4★sanjary 16●1●1●4 accept rate: 0% but if it throws an exception then it will not execute the code...then u'll get a WA....it is better if u check if your input format is correct..i.e while using bufferedReader and specially while using the readLine() function...also u should take care array out of bounds excep....the above format will only help to find where the error is occurring and that to only if u have the specific cases..as the example cases or many small cases may pass...:) (05 Aug '13, 17:10) kunal3614★ NO actually you see, it's not like that! That's the convention how you write it at the beginning at the function. It's a built-in exception class. The way I coded is similar to something like below and both means the same, just different convention or writing practice- public static void main(String[] args { try{ //Your Solve }catch(IOException e){ System.err.println(e.getMessage()); return; } }  (12 Aug '13, 02:56) sanjary4★ One thing I've noticed is using string tokenizer to parse input is always better than using split function. The latter many times lead to IOException/NZEC. (13 Jul '15, 16:07) aj954★

 1 NZEC means "Non zero exit code". Its essentially saying that your program ran into some error during execution. Mostly, it comes up when there is a Segmentation Fault. The SegFault can be caused by many things, but experience says it is mainly through two causes: (a) Infinite Recursion - or basically when you run out of stack memory. (b) Incorrect Memory Access - or whenever there is some weird stuff happening with memory allocation / access. C++ isn't so friendly as Java, and it will not explicitly tell you that you have an "ArrayIndexOutOfBounds Exception", but will instead try to use the "supposed" memory even if it is outside the block. This makes things a bit hard to debug. If you're accessing things far out for example. Some sample codes that should give NZEC on Codechef/Spoj: Example 1: DFS void dfs(int u) { visited[u]++; for(int v = 0; v < N; v++) if(adjmat[u][v] == 1) dfs(v); } answered 19 Mar '17, 14:10 2★vivek96 518●2●12 accept rate: 7%
 0 My code runs well in my laptop but gets Runtime Error (NZEC) while submitting it... Why it is so ? answered 12 Jul '15, 14:12 11●1 accept rate: 0%
 0 I have a code that is correct but giving NZEC when submitted. How can i post the code i wrote for discussing it with others? answered 12 Jul '15, 18:34 0★seanshow 1 accept rate: 0% please post ur code (19 Mar '17, 14:02) vivek962★ post your code using "code" html tag or link your code. (09 Feb, 11:54)
 0 please check your solution, sometimes it is just because of your solution is giving wrong answer, try all possible cases as you can. I faced it recently and have gone through all possible cases and got to know that one of test case was failing and after changing my code accordingly, codechef has accepted my solution:) answered 19 Mar '17, 13:48 2★anitab 1 accept rate: 0%
 0 did that exception thing but my laptop is showing perfectly right answer.... in that case where should i start looking error in my code.. answered 12 Apr '17, 10:30 1 accept rate: 0%
 0 If you are submitting the code by copying from your IDE, make sure you select the code from import statements not from your package statement. This will also give you NZEC error. Please check your submission. answered 12 Apr '17, 12:31 61●4 accept rate: 0%
 0 import java.util.*; public class Main{ public static final double BANK_CHARGES = 0.50; public static void main(String[] args) { Scanner console = new Scanner (System.in); System.out.printf("\t\tInput : \n\t\t"); int x = console.nextInt(); double y = console.nextDouble(); check(x,y); y=y-x-BANK_CHARGES; output(y); } public static void check(int x, double y){ if (x%5!=0){ output(y); System.out.printf("\n\t\tIncorrect Withdrawble Amount (not multiple of 5)\n\n"); throw new IllegalArgumentException( ); } else if ((y-x-BANK_CHARGES)<0){ output(y); System.out.printf("\n\t\tInsufficient Fund\n\n"); throw new IllegalArgumentException(); } } public static void output(double y){ System.out.printf("\n\t\tOutput :\n\t\t%.2f",y); }  } answered 08 Oct '17, 17:21 1 accept rate: 0% NZEC error ... This code runs well in my laptop but gets Runtime Error (NZEC) while submitting it (08 Oct '17, 17:24)
 0 import java.util.*; class Main { public static void main (String arg[]) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int arr[] = new int[n]; for(int i=0;i
 0 I DONT UNDERSTAND WTF IS WRONG IN MY CODE ITS PERFECTLY WORKING ON JDK 9 AND CODECHEF IS SAYING IT HAS NZEC RUNTIME ERROR / * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. / import java.io.; import java.util.; / * @author Aashlesh Dhumane / public class Main { /** * @param args the command line arguments * @throws java.lang.Exception */ public static void main(String[] args) throws Exception { // TODO code application logic here int n; int i,j,k,l; System.out.println("enter the test cases"); String str; BufferedReader b = new BufferedReader (new InputStreamReader(System.in)); str=b.readLine(); n=Integer.parseInt(str); // for (i=0;i0) { str=b.readLine(); i=Integer.parseInt(str); str=b.readLine(); j=Integer.parseInt(str); str=b.readLine(); k=Integer.parseInt(str); str=b.readLine(); l=Integer.parseInt(str); if ((i==j && k==l) || (j==k && l==i) || (i==k && j==l) ) {System.out.println("YES"); } else { System.out.println("NO"); } n--; } }  } answered 11 Jan, 12:29 1 accept rate: 0% Try using fast I/O given in geeksforgeeks.com . If the error still persists, get back to us. (11 Jan, 18:27)
 0 Alright I don't seem to have a high enough Karma or something to ask a separate question so I thought I'd post it here since the topic is related. I keep getting an NZEC error at the spot I marked by a comment in my code when running it on the online IDE set to the problem CHEFCHR (I'm aware the contest is still going on which is why I omitted specific code to prevent illegal use): /* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int cases = sc.nextInt(); //THE NZEC ERROR IS HAPPENING HERE for(int i = 0;i < cases;i++) { String s = sc.next(); /* Omitted code for sake of confidentiality since the contest is still running */ } } } Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at Codechef.main(Main.java:14)  When I run this code in my ide (NetBeans), I'm fine and everything works perfectly. When I run it on the online IDE with custom input, everything is fine as well. When I run it with the CHEFCHR input, I'm given an NZEC error. When I've been submitting, it's been telling me my code gives the wrong answer. Even if I run LITERALLY ONLY the code below, I get the same exact NZEC error: import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int cases = sc.nextInt(); } } Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at Codechef.main(Main.java:11)  What am I doing wrong if even just calling for scanner to read in an integer is giving me an error? answered 08 Feb, 05:31 1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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,133
×486
×387
×260
×112
×28

question asked: 05 Aug '13, 14:28

question was seen: 37,124 times

last updated: 11 Jun, 20:05