This week's book giveaway is in the Java in General forum. We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line! See this thread for details.
N Sahni wrote:Here is the sample code for getting user input in Java through command-line: . . .
But you didn't close the Readers.
Which is a good thing in this case. Closing the Readers would close System.in which will cause it to become useless within the entire JVM until it exits.
Just saw that readLine() can take a prompt. So this is N Sahni's example in Java 6.
Of course, you could make it shorter by in-lining the expression for value, at a slight cost to readability.