首页 > 编程语言 > 详细

[Java]String.format(); System.out.printf(); System.out.format()

时间:2020-05-27 11:15:35      阅读:46      评论:0      收藏:0      [点我收藏+]

 

 

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("\t%s got a 20%% off, so he paid $%,.3f for his new car.%n", "George", cost);
        System.out.print(descOfPrice);

//注:
//flags %,.3f
//%% 来输出%
//我们用%n来换行,而不用\n
//%t 没用,还用\t
    }
}

 

[Java]String.format(); System.out.printf(); System.out.format()

原文:https://www.cnblogs.com/profesor/p/12971289.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!