跳到主要內容

Java String Format

java練習筆記
String Format延伸應用:

  • fix position : left justified()
          System.out.println(String.format("%-10s hello" , s1));
          hello      java

  • fix position : right justified()
          System.out.println(String.format("%10s helllo" , s1));
               hello java
  • fill zero in front
          String.format("%03d" ,  s1)
          050

留言