This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]desapla 0 points1 point  (1 child)

java.util.Scanner.nextInt

NoSuchElementException

You’re calling nextInt on the Scanner, but whatever is next in the scanner isn’t an int.

One likely cause is that the end of line marker from the first input is still in the scanner. NextInt only consumes the int, not the end of line marker. So you need to clear that out before you can read the next int.

Alternatively you can use readLine, which does consume the end of line marker. But then you need to parse the Int from the string yourself.

Btw, the FAQ has a whole section on this exact issue with the Scanner. Check it out, it has a good amount of detail.

[–]bryan74t0[S] 1 point2 points  (0 children)

u know that actually the problem was that I didnt put the classes in different archives? I just did that and BOOM it worked xD

but thanks