Closing a Scanner
causes the underlying InputStream
to be closed also. As there is only one System.in
, any newly created Scanner
objects will not be able to read from the same stream:
r.close();
This line should be removed
See: Do not create multiple buffered wrappers on a single InputStream