This simple example shows how to get the standard input from console in Java. When you run this program, it asks the user for the input, if you enter a value, it is printed in the console. Let’s try this example.
StdInputExample.java
package javabeat.net.core; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class StdInputExample { public static void main(String args[]) { try { //BufferedReader with InputStreamReader BufferedReader bufferReader = new BufferedReader(new InputStreamReader( System.in)); String inputValue; //Reads and prints it while ((inputValue = bufferReader.readLine()) != null) { System.out.println("You entered : "+inputValue); } } catch (IOException io) { io.printStackTrace(); } } }