Example usage for java.util Formatter Formatter

List of usage examples for java.util Formatter Formatter

Introduction

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

Prototype

public Formatter() 

Source Link

Document

Constructs a new formatter.

Usage

From source file:MainClass.java

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

    for (double i = 1000; i < 1.0e+10; i *= 100) {
        fmt.format("%g ", i);
        System.out.println(fmt);/*from   w  ww.  ja v a  2 s .  c  o m*/
    }
}

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);/* ww w  . ja v a  2 s.c  o m*/

}

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);/* ww w  .  j  av a2 s. co  m*/

}

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);/*  w ww .  j av a 2  s  .  co  m*/

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

From source file:Main.java

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

    fmt.format("%-12s %12s\n\n", "Source", "Loss");
    fmt.format("%-12s %,12d\n", "Retail", 1232675);

    System.out.println(fmt);/* w ww  .j  av  a2s  .  c  o m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Formatter fmt = new Formatter();
    fmt.format("Default positive and negative format: %.2f %.2f\n", 423.78, -505.09);
    fmt.format("With + and parentheses: %+.2f %(.2f\n", 423.78, -505.09);
    System.out.println(fmt);//from ww  w .  j  a v a2 s  .  co m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Formatter fmt = new Formatter();
    fmt.format("Default precision: %f\n", 10.0 / 3.0);
    fmt.format("Two decimal digits: %.2f\n\n", 10.0 / 3.0);
    System.out.println(fmt);//from www  .  j  a  va 2s  .  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   w  w  w.ja  v  a2 s .  com
}

From source file:Main.java

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

    fmt.format("No group separators: %d\n", 123456789);
    fmt.format("With group separators: %,d\n\n", 123456789);
    System.out.println(fmt);//ww w.j  ava2s  .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);/*w  w w  . j a v a 2  s  .c om*/
}