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

×

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

1
3

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

sanjary's gravatar image

4★sanjary
16114
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★

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); }

link

answered 19 Mar '17, 14:10

vivek96's gravatar image

2★vivek96
518110
accept rate: 7%

My code runs well in my laptop but gets Runtime Error (NZEC) while submitting it... Why it is so ?

link

answered 12 Jul '15, 14:12

kislaya123's gravatar image

2★kislaya123
111
accept rate: 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?

link

answered 12 Jul '15, 18:34

seanshow's gravatar image

0★seanshow
1
accept rate: 0%

please post ur code

(19 Mar '17, 14:02) vivek962★

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:)

link

answered 19 Mar '17, 13:48

anitab's gravatar image

2★anitab
1
accept rate: 0%

edited 19 Mar '17, 13:49

did that exception thing but my laptop is showing perfectly right answer.... in that case where should i start looking error in my code..

link

answered 12 Apr '17, 10:30

anonymous_9093's gravatar image

2★anonymous_9093
1
accept rate: 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.

link

answered 12 Apr '17, 12:31

sai_praneeth's gravatar image

2★sai_praneeth
614
accept rate: 0%

edited 12 Apr '17, 12:33

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);
}

}

link

answered 08 Oct '17, 17:21

rabbit_404's gravatar image

0★rabbit_404
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) rabbit_4040★
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<n;++i) {
      arr[i] = scan.nextInt();
   }
   System.out.println(rec(arr,n));
}
public static int rec(int arr[],int n){
   if(n==0){
     return 0;
   }
   if(n==1){
     return arr[0];
   }
   if(n==2) {
     if(arr[0]<arr[1])
        return arr[0];
     else
       return arr[1];
   }
   int mat[] = new int[n];
   mat[0] = arr[0];
   mat[1] = arr[1];
   mat[2] = arr[2];
   for(int i=3;i<n;++i) {
     mat[i]=arr[i]+min(mat[i-1],mat[i-2],mat[i-3]);
   }
   return min(mat[n-1],mat[n-2],mat[n-3]);
 }
 public static int min(int a,int b,int c){
   if(a<=b && a<=c){
     return a;
   }else if(c<=b && c<=a){
     return c;
   } else{
     return b;
   }
 }
}

This code runs well in my laptop but gets Runtime error(NZEC) while submitting, please help.

link

answered 25 Dec '17, 14:29

saku_19's gravatar image

2★saku_19
1
accept rate: 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;i<n;i++)
   // {
   while (n>0)
   {
    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--;     
   }


    }

}

link

answered 11 Jan, 12:29

deadlydanson's gravatar image

1★deadlydanson
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) vijju123 ♦5★
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,075
×448
×337
×227
×92
×27

question asked: 05 Aug '13, 14:28

question was seen: 29,563 times

last updated: 11 Jan, 18:27