集册 Java实例教程 右对齐和左对齐值

右对齐和左对齐值

欢马劈雪     最近更新时间:2020-01-02 10:19:05

374
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
右对齐和左对齐值

public class Main 

{

   public static void main(String[] args)/* from NowJava.com - 时  代  Java*/

   { 

      System.out.println("Columns:");

      System.out.println("0123456789012345678901234567890123456789\n");

      System.out.printf("%10s%10d%10c%10f\n\n", "hello", 7, 'a', 1.23);

      System.out.printf(

         "%-10s%-10d%-10c%-10f\n", "hello", 7, 'a', 1.23);

   } 

}