Runtime Error NZEC

匿名 (未验证) 提交于 2019-12-03 01:44:01

问题:

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

I don't know how to remove NZEC error;

problem:http://www.spoj.com/problems/PALIN/

Explain the error in program.

回答1:

NZEC means that the compiler got an uncaught exception, but didn't bother to output it properly. I heard that SPOJ's Java compiler does this, and sometimes it happens when it doesn't terminate input properly. Try wrapping your code in a try - catch block like this:

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

That is, of course, if your code doesn't throw other uncaught exceptions on some test cases. You'd want to check that, too.

(Adapted from this answer to what NZEC is)



回答2:

error is because in that question length of number is up to 1000000 digits and long datatype is unable to store such large number so it gives error try using BigInteger ..In given question you can solve it by using String



文章来源: Runtime Error NZEC
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!