import java.io.*; public class Test { public static void main(String args[]) throws IOException { int x = 123; double y = 3.141592654; String z = "abcde", out; // 文字列のフォーマット out = String.format("%0+7d %2$10.4f %10.2f %s", x, y, z); System.out.println(out); // 出力をフォーマット System.out.printf("%3$0+7d %2$10.4f %1$s\n", z, y, x); System.out.printf("%0+7d %10.4f %s\n", x, y, z); } }
+000123 3.1416 3.14 abcde +000123 3.1416 abcde +000123 3.1416 abcde