集册 Java实例教程 右对齐字段中的整数。

右对齐字段中的整数。

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

429
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
右对齐字段中的整数。

public class Main //NowJava.com - 时代Java 提 供

{

   public static void main(String[] args)

   { 

      System.out.printf("%4d\n", 1);

      System.out.printf("%4d\n", 12);

      System.out.printf("%4d\n", 123);

      System.out.printf("%4d\n", 1234);

      System.out.printf("%4d\n\n", 12345); // data too large 


      System.out.printf("%4d\n", -1);

      System.out.printf("%4d\n", -12);

      System.out.printf("%4d\n", -123);

      System.out.printf("%4d\n", -1234); // data too large 

    
展开阅读全文