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:6)
I got this error in every program
hi @lukharshiv
send me your code or do the following
When using Scanner class for input, check if the Scanner object sc hasNextInt() and/or hasNext() or not for int and string inputs lets say, before just trying to take the input.
And this will resolve the error.
Example -
For string input :
if(sc.hasNext())
{
String s = sc.next();
}
And for integer input :
if(sc.hasNextInt())
{
int n = sc.nextInt();
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.