Scanner 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 Codechef.main(Main.java:14)

Giving run time error : NZEC
I am getting error while taking input with scanner .
If I run same code in eclipse I am not getting any error.

Code snippet:

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner inp=new Scanner(System.in);
int t=inp.nextInt();
System.out.println(“a”);
}
}

The error you are facing can be resolved by ticking on Custom Input and give the input you want.In java, if you use Scanner then you have to tick custom input, I do not know why in online IDE it is compulsory but you have no choice if you are using Scanner.

Hope this will help you!!! @srikar_ganta

2 Likes

Which problem are you talking about? Also, could you give us the submission link?

1 Like