Do not use scanner.close()<- the source of your error!
delete lines scanner.close()andnewScanner.close()
From Java DOC:
When the scanner is closed, it will close its input source if the source implements the Closeable interface.
That means it closes System.in- a bad choice!
From the source code Scanner.javain the JDK, throwFor():
private void throwFor() {
skipped = false;
if ((sourceClosed) && (position == buf.limit()))
throw new NoSuchElementException();
else
throw new InputMismatchException();
}
, , , , NoSuchElementException(). , IDEONE - position == buf.limit(), sourceClosed