Get user input in Java

By: Marcus Viewed: 1387 times  Printer Friendly Format    

This Java program prompts the user to enter the name by using System.out.print() method to keep the cursor on the same line. Then using the object, along with the InputstreamReader and BufferedReader classes the user input is read. The br.readline() method reads the name from the command line. After pressing the enter key, you will get the user input.


public class GetUserInput {
    public static void main (String[] args) {
       System.out.print("Enter your name and press Enter: ");
       BufferedReader br = new BufferedReader(new InputStreamReader(;
       String name = null;
       try {
         name = br.readLine();
       } catch (IOException e) {
       System.out.println("Your name is " + name);

Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial