-3

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.

jignesh Vadadoriya
  • 3,244
  • 3
  • 18
  • 29
Musicjay
  • 1
  • 3
  • You tried inserting it *where*? – chrylis -cautiouslyoptimistic- Jan 07 '17 at 05:08
  • 1
    your code is running perfectly in my netbeans. – Kaushal28 Jan 07 '17 at 05:13
  • You need to provide more explanation. What input produces this exception ? What is your desired output ? – Yousaf Jan 07 '17 at 05:13
  • Well, this is the error that would occur if you call `nextInt`, and the input is exhausted. I.e. there's **no such element**. Your input must have 3T integers after reading T. It probably doesn't. It would also be very easy to add a `println` or two to determine how far it's getting. Programmer heal thy self. – Gene Jan 07 '17 at 05:19
  • The program is for a competitive programming contest. I'm only dependent on an example input they're providing to check my program. I have no clue what kind of input they're giving, but my BlueJ shows me the correct information for each input I give, at least. – Musicjay Jan 07 '17 at 05:34

1 Answers1

-1

"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.

walla
  • 1
  • 1