java - 代码厨师 : Runtime Error (NZEC)

标签 java runtime-error

我尝试了 codechef 的一个问题,并在 java 上编写了我的代码,该代码在我的笔记本电脑上的 eclipse 上完美运行。但是每次我尝试提交代码时,它都会给我这个 NZEC 错误。 谁能告诉我为什么在执行此代码时出现非零退出代码错误(NZEC)。 此代码的问题: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");

        }
    }
}

最佳答案

您的代码存在的问题是,在从用户获取 String A 和 B 的输入时,readline() 方法返回 null,并且当您尝试访问 String A 或 B 时,会引发 NullPointerException。因此是非零退出代码。

现在,readline() 方法返回了 null 值,因为您两次创建了 BufferedReader 对象,从而导致了内存泄漏。

引用此链接:readline() returns null in Java

关于java - 代码厨师 : Runtime Error (NZEC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36047221/

相关文章:

java - Dagger 2 - 字段注入(inject)中的空指针

java - 在Java中如何向没有空格的变量添加字符?

java - JOptionPanel 上出现不可预测的 java 程序运行时错误

android - 得到错误 : Caused by: android. database.sqlite.SQLiteException: near "of"

python - Python 中的 "IOError: [Errno 0] Error"错误

Java错误api级别的方法

java - Spring MVC Hello World 应用程序在 AWS elastic beanstalk 上出现 404 错误,在本地按预期运行

java - 命名谓词

java - 如何从 cassandraexecuteAsync() 方法调用方法抛出异常

c++ - 堆栈运行时错误