public class FORMAT { public static void main(String[] args) { String name = "jerry"; int age = 50; System.out.printf("My name is %s, and I'm %d years old.%n", name, 55); System.out.format("%s is %d years old.%n", "George", age + 3); //printf与format用法一样 double cost = 83456.34567; String descOfPrice = String.format(" %s got a 20%% off, so he paid $%,.3f for his new car.%n", "George", cost); System.out.print(descOfPrice); //注: //flags %,.3f //%% 来输出% //我们用%n来换行,而不用 //%t 没用,还用 } }