Home java Why gives NosuchelementException and how to solve it?

Why gives NosuchelementException and how to solve it?

Author

Date

Category

Error:

exception in thread "main" java.util.nosuchelementException
  at java.base / java.util.scanner.throwfor (scanner.java:937)
  at java.base / java.util.scanner.next (scanner.java:1594)
  at java.base / java.util.scanner.nextint (scanner.java:2258)
  at java.base / java.util.scanner.nextint (scanner.java:22)
  at main.main (main.java:10)

Answer 1

paiza.io Streaming is specified immediately, in advance, and does not request to the user with each reading.

You need to specify all the input data in advance in the input field, then your program will work.

And do not forget at the end of the program to add sc.close () so that the process does not eat memory. Good tone rule.

Hope your problem was precisely in this (your program read empty input)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions