NoSuchElement exception error in particular program

I have used Scanner for all my programming needs, but for some reason, I'm unable to get through this error:

Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at Main.main(Main.java:9)

In the following code:

import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
    public static void main(String args[]) throws java.lang.Exception
    {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        if(T>0&&T<Math.pow(10,5))
        {
            String ans[]=new String[T];
            int a=0;
            int C=0,D=0,L=0;            
            for(a=0;a<T;a++)
            {
                C=in.nextInt();
                D=in.nextInt();
                L=in.nextInt();
                if(L>(C*4)+(D*4)||L<(C/D)*4+(C%D)*4||L%4!=0)
                ans[a]="no";
                else
                ans[a]="yes";
            }
            a=0;
            while(a<T)
            {
                System.out.println(ans[a]);
                a++;
            }
        }
    }
}

I have gone through all the questions regarding the said error, but am not able to solve my problem. I have also tried inserting in.hasNextInt() too, but the error persists.


"Thrown by the nextElement method of an Enumeration to indicate that there are no more elements in the enumeration." - from JDK7 doc. "Thrown by various accessor methods to indicate that the element being requested does not exist." - from JDK8 doc ( link ). For me, this code is working fine.

链接地址: http://www.djcxy.com/p/96100.html

上一篇: 扫描程序抛出NoSuchElementException

下一篇: NoSuchElement特殊程序中的异常错误