运行时错误NZEC

时间:2015-02-16 07:22:57

标签: java

import java.util.Scanner;

public class FindSmallestPalindrome {

    public static void main(String args[]){ 

        Scanner s = new Scanner(System.in);
        //System.out.println("Enter the number");
        int testCase = s.nextInt(),i=1;
        long st;
        StringBuilder str = new StringBuilder();
        while(i <= testCase){         
            st  = s.nextLong();
            st +=1;                     

            while(st <= 1000000000){
                str.append(st);
                //System.out.println("str="+str);
                if(str.reverse().toString().equals(st+"")){
                    //System.out.println("str inside="+str);
                    System.out.println(st);
                    break;
                }
                str.delete(0,str.length());
                st++;
                //System.out.println("temp="+st);
            }
            i++;
        }
    }
}

我不知道如何消除NZEC错误;

问题:http://www.spoj.com/problems/PALIN/

解释程序中的错误。

2 个答案:

答案 0 :(得分:0)

NZEC意味着编译器得到了一个未捕获的异常,但没有打算正确输出它。我听说SPOJ的Java编译器会这样做,有时它会在没有正确终止输入的情况下发生。尝试将代码包装在try - catch块中,如下所示:

try{
    /* Your code */
} catch(Exception e){
    return;
}

当然,也就是说,如果您的代码在某些测试用例中没有抛出其他未捕获的异常。你也想检查一下。

(改编自this answer to what NZEC is

答案 1 :(得分:0)

错误是因为在那个问题中,数字长度最多为1000000位,而长数据类型无法存储如此大的数字,因此使用BigInteger会出错。在给定的问题中,您可以使用String解决它

相关问题