3. Java – Get User Input

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class HelloWorld {
public static void main(String[] args) throws IOException
{
  System.out.println("Please Enter your Name : ");
  // Enter data using BufferReader
  BufferedReader reader = new BufferedReader(
  new InputStreamReader(System.in));
  // Reading data using readLine     
  String name = reader.readLine();     
  // Printing the read line     
  System.out.println(" User Entered : "+name); }
 }

Reading input needs a “InputStreamReader” but you can initiate it only with a BufferedReader.

You are enabling “system.in” the console(ms-dos or linux terminal in this case) reading.

Output:

%d bloggers like this: