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








Syntax

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

public Console format(String fmt,  Object ... args)

Example

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

//from  ww w. j  a va2 s . c o m
import java.io.Console;

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

    Console cnsl = System.console();

    if (cnsl != null) {
      String fmt = "%1$4s %2$10s %3$10s%n";

      // format
      cnsl.format(fmt, "Items", "Level", "Price");
      cnsl.format(fmt, "-----", "-----", "-----");
      cnsl.format(fmt, "PHP", "1", "15");
      cnsl.format(fmt, "CSS", "2", "50");
      cnsl.format(fmt, "Java", "3", "30");
      cnsl.format(fmt, "HTML", "4", "80");
    }

  }
}

The code above generates the following result.