Scanner continuous loop <p>Why isn't my inputScanner blocking after the first input? It goes into a continous loop. Ignore other details of this code.</p> <pre><code>public class Test { public static void main(String[] args) { boolean finished; do { Scanner inputScanner = new Scanner(System.in); finished = inputScanner.hasNext("exit"); boolean validNumber = inputScanner.hasNextDouble(); if (validNumber) { double number = inputScanner.nextDouble(); System.out.print(number); } else if (!finished) { System.out.println("Please try again."); } inputScanner.close(); } while (!finished); } } </code></pre> <p><strong>EDIT:</strong> On a previous post which was related to this, it was mentioned that "So if you are going use System.in later don't close it (if it is closed, we can't reopen it and read any data from it, hence exception)". Why is this happening? </p>