Java: Exemple d’utilisation de printf

Author:


Download

 
public class PrintfMots {
  public static void main(String[] args) {
 
    String [] mots = new String [] { "x", "sakoba", "abcdefghijklmnopqrstvuwxyz" };
    System.out.printf( "%-10s %sn", "mot", "Longuer" );
    for ( String mot : mots )
      System.out.printf( "%-10.10s %sn", mot, mot.length() );
 
  }
 
}
/*
mot        Longuer
x          1
sakoba     6
abcdefghij 26
*/