Reputation: 51
I attempted a problem from codechef and made my code on java which runs perfectly on eclipse on my laptop.But everytime i try to submit the code it gives me this NZEC error. Can anyone tell why am i getting the non zero exit code error (NZEC) while i am executing this code. Problem to this code: https://www.codechef.com/problems/STRPALIN
import java.util.*;
import java.io.*;
public class Palindrome {
public boolean check() throws IOException{
String A;
String B;
BufferedReader inp = new BufferedReader (new InputStreamReader(System.in));
A=inp.readLine();
B=inp.readLine();
for(int i=0;i<A.length();i++)
{
for(int j=0;j<B.length();j++)
{
if(A.charAt(i)==B.charAt(j))
return true;
}
}
return false;
}
public static void main(String[] args)throws NumberFormatException, IOException {
Palindrome M = new Palindrome();
boolean[] array = new boolean[10];
BufferedReader in = new BufferedReader (new InputStreamReader(System.in));
int T = Integer.parseInt(in.readLine());
for(int i=0;i<T;i++)
{
array[i]=M.check();
}
for(int j=0;j<T;j++){
if(array[j])
System.out.println("Yes");
else
System.out.println("No");
}
}
}
Upvotes: 1
Views: 441
Reputation: 1085
Regarding the NZEC error:
import java.util.*;
import java.io.*;
class Codechef {
public boolean check() throws IOException{
String A;
String B;
BufferedReader inp = new BufferedReader (new InputStreamReader(System.in));
A=inp.readLine();
B=inp.readLine();
for(int i=0;i<A.length();i++)
{
for(int j=0;j<B.length();j++)
{
if(A.charAt(i)==B.charAt(j))
return true;
}
}
return false;
}
public static void main(String[] args)throws NumberFormatException, IOException {
try {
Codechef M = new Codechef();
boolean[] array = new boolean[10];
BufferedReader in = new BufferedReader (new InputStreamReader(System.in));
int T = Integer.parseInt(in.readLine());
for(int i=0;i<T;i++)
{
array[i]=M.check();
}
for(int j=0;j<T;j++){
if(array[j])
System.out.println("Yes");
else
System.out.println("No");
}
} catch(Exception e) {
} finally {
}
}
}
Upvotes: 0
Reputation: 11
The problem with your code is that while taking input from user for String
A and B, the readline()
method returns null
, and when you try to access String
A or B, a NullPointerException
is thrown. Hence the non-zero exit code .
Now, the readline()
method returned null
value because you created a BufferedReader
object twice, which led to leakage of memory.
Refer to this link: readline() returns null in Java
Upvotes: 0