我在codechef中收到NZEC错误

时间:2015-11-11 06:10:52

标签: java

在codechef中提交此代码时出现NZEC错误。

import java.util.Scanner;
class Codechef 
{

    public static void main(String[] args)throws java.lang.Exception 
    {
        Scanner sc=new Scanner(System.in);
        int test=sc.nextInt();
        for(int i=1; i<=test; i++)
        {
            int n=sc.nextInt();
            Integer num=n;
            int length=(int)Math.pow(10, num.toString().length()-1);
            while(length>0)
            {
                System.out.println(num);
                num%=length;
                length/=10;
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

如果你有一个输入文件,其中要跟随的整数数大于实际的整数数,则nextInt会抛出NoSuchElementException。

使用hasNextInt测试输入中其他数字的可用性。

for(int i=1; i<=test; i++){
    if( sc.hasNextInt() ){
        int n=sc.nextInt();
        // etc.
    }
}
相关问题