Java Console readLine() Example

Console class readLine() method example. This example shows you how to use readLine() method.


Syntax is : public String readLine(String fmt, Object... args)
This method provides a formatted prompt, then reads a single line of text from the console.

Here is the code.

/**
 * @(#) ReadLine1Console.java
 * A class representing use of method readLine() of Console class in 
java.io Package.
 * @Version  11-June-2008
 @author   Rose India Team
 */
import java.io.*;

public class ReadLine1Console {

    public static void main(String[] args) {

        //Create a console object.
        Console objConsole = System.console();
        if (objConsole != null) {
            String formatString = "%1$4s %2$5s %3$10s%n";

            // readLine method call.
            String name = objConsole.readLine(formatString, "Please""Enter"
                    "Your Name :");
            System.out.println("You have entered : " + name);
        }
    }
}

Output of the program.
 Please Enter Your Name :
mahendra singh
You have entered : mahendra singh

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US