How to close a scanner without closing the underlying System.in?
问题 If I close one scanner object and make a new one and try to read some more input, I'm getting the NoSuchElementException exception. My code works fine but it gives me a warning if I don't close the scanner. However, if I close it to get rid of the warning, I also close System.in ... How do I avoid this? Also, are there any consequences of not closing the scanner? EDIT: Here's my code: This is the NameAddressExists() method: public void NameAddressExists() { System.out.println("Enter name");