How to Read User Input from Console using Console class in Java?

Below java code show how to read user input from Console using Console java class

/****************************************************************************************
 * Created on 08-2011 Copyright(c) https://kodehelp.com All Rights Reserved.
 ****************************************************************************************/
package com.kodehelp.java.io;

import java.io.Console;

/**
 * Created by Vigilance India.
 * User: https://kodehelp.com
 * Date: Aug 4, 2011
 */
public class ReadInputFromConsole {
    public static void main(String [] args){

        //Create Console instance from System.console();
        Console console = System.console();

        // Read First Name from Console
        String firstName = console.readLine("First Name:: ");
        //Read Last Name from Console
        String lastName = console.readLine("Last Name:: ");

        System.out.println("Welcome Mr."+firstName +" "+lastName);
    }
}

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.