Java IO Tutorial - Java Console.readLine(String fmt, Object ... args)








Syntax

Console.readLine(String fmt, Object ... args) has the following syntax.

public String readLine(String fmt,  Object ... args)

Example

In the following code shows how to use Console.readLine(String fmt, Object ... args) method.

/* w  w w  .  j ava2  s . c o  m*/

import java.io.Console;

public class Main {
  public static void main(String[] args) throws Exception {

    String fmt = "%1$4s %2$5s %3$10s%n";

    Console cnsl = System.console();

    // if console is not null
    if (cnsl != null) {

      // read line from the user input
      String alpha = cnsl.readLine(fmt, "Enter", "Alphabets: ");

      // prints
      System.out.println("Alphabets entered: " + alpha);
    }

  }
}

The code above generates the following result.