有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我在codechef中遇到一个NZEC错误

在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) 个答案

  1. # 1 楼答案

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

    使用hasNextInt测试输入中另一个数字的可用性

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