Classe Formatter: Exemple de justification à gauche et à droite

Author:


{filelink=5762}

import java.util.Formatter;

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

       // Justification à gauche.
	  fmt = new Formatter();
	  fmt.format("|%-10.2f|", 3.14159);
      System.out.println(fmt);

      // Justification à droite
      fmt.format("|%10.2f|", 3.14159);
      System.out.println(fmt);

    }
}

/**
 *Affichage:
|3,14      |
|3,14      ||      3,14|
 */

Leave a Reply

Your email address will not be published. Required fields are marked *