Example usage for java.util Formatter format

List of usage examples for java.util Formatter format

Introduction

In this page you can find the example usage for java.util Formatter format.

Prototype

public Formatter format(String format, Object... args) 

Source Link

Document

Writes a formatted string to this object's destination using the specified format string and arguments.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();

    fmt.format("% d", -100);
    System.out.println(fmt);//from  w  w  w  . j  a va2s .  c o  m

    fmt = new Formatter();
    fmt.format("% d", 100);
    System.out.println(fmt);

    fmt = new Formatter();
    fmt.format("% d", -200);
    System.out.println(fmt);

    fmt = new Formatter();
    fmt.format("% d", 200);
    System.out.println(fmt);
}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();

    fmt = new Formatter();
    fmt.format("%.15s", "Formatting with Java is now easy.");
    System.out.println(fmt);/*from   w  w w .j  av a 2  s .c  om*/
}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();

    fmt = new Formatter();
    fmt.format("%16.2e", 123.1234567);
    System.out.println(fmt);//from   w  w  w. ja va  2 s .  c om

}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();
    // Right justify by default 
    fmt.format("|%10.2f|", 123.123);
    System.out.println(fmt);//from   www.j  ava 2 s.c  o  m
}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();
    // Format 4 decimal places. 
    fmt.format("%.4f", 123.1234567);
    System.out.println(fmt);//from   www . j a v a 2  s.  com
}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();

    // Right justify by default.
    fmt.format("%+d", 100);
    System.out.println(fmt);/*from   w w w  . j a v a  2 s  .  c o m*/

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Formatter fmt = new Formatter();
    Calendar cal = Calendar.getInstance();
    fmt.format("Hour and Minute: %tl:%1$tM %1$Tp\n", cal);
    // Display the formatted times and dates.
    System.out.println(fmt);// w  ww  .ja v  a 2 s  .  c  om
}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();

    // Right justify by default.
    fmt.format("|%10.2f|", 123.123);
    System.out.println(fmt);//  www  .  j  av a 2 s  .c  o m

    // Now, left justify.
    fmt = new Formatter();
    fmt.format("|%-10.2f|", 123.123);
    System.out.println(fmt);
}

From source file:MainClass.java

public static void main(String args[]) {
    Formatter fmt = new Formatter();

    // ./* w w w. j av a2 s  .com*/
    fmt = new Formatter();
    fmt.format("%tc", Calendar.getInstance());
    System.out.println(fmt);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Formatter fmt = new Formatter();
    Calendar cal = Calendar.getInstance();

    fmt.format("Time using 24-hour clock: %tT\n", cal);
    System.out.println(fmt);/*from  w  w  w  .  j av  a  2s .  com*/

}