简体   繁体   中英

I am getting an NZEC error in codechef

Getting an NZEC error while submitting this code in codechef.

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

If you have an input file where the number of integers to follow is greater than the actual number of integers, nextInt throws a NoSuchElementException.

Use hasNextInt to test the availability of another number in the input.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM