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) All Rights Reserved.


 * Created by Vigilance India.
 * User:
 * 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.