[%0*.0f]的printf用法

printf("[%0*.0f]/n", 8, 88833.3);
    printf("[%0*.0f]/n", 9, 88833.3);
    printf("[%0*.0f]/n", 10, 88833.3);
    printf("[%0*.0f]/n", 11, 88833.3);
    printf("[%0*.0f]/n", 12, 88833.3);
    printf("[%0*.0f]/n", 13, 88833.3);
    printf("[%0*.0f]/n", 14, 88833.3);
    printf("[%0*.0f]/n", 15, 88833.3);
    printf("[%0*.0f]/n", 16, 88833.3);
    printf("[%0*.0f]/n", 17, 88833.3);
    printf("[%0*.0f]/n", 18, 88833.3);
    printf("[%0*.0f]/n", 19, 88833.3);
    printf("[%0*.0f]/n", 20, 88833.3);

的输出结果是:

[00088833]
[000088833]
[0000088833]
[00000088833]
[000000088833]
[0000000088833]
[00000000088833]
[000000000088833]
[0000000000088833]
[00000000000088833]
[000000000000088833]
[0000000000000088833]
[00000000000000088833]。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以将 Circle 类中的 Radius 成员变量改为私有变量并提供一个访问器方法: ``` public class Circle { private double radius; // 将 Radius 改为小写的 radius public Circle() { radius = 0; } public Circle(double r) { radius = r; } public double getRadius() { // 添加访问器方法 return radius; } public double getArea() { return Math.PI * radius * radius; } public double getPerimeter() { return 2 * Math.PI * radius; } public void show() { System.out.printf("圆半径:%.1f\n", radius); System.out.printf("圆周长:%.3f\n", getPerimeter()); System.out.printf("圆面积:%.3f\n", getArea()); } } ``` 还可以在 Cylinder 类中添加一个 show() 方法来展示圆柱的基本信息和附加信息: ``` public class Cylinder extends Circle { private double height; public Cylinder(double r, double h) { super(r); height = h; } public double getVolume() { return super.getArea() * height; } public double getSurface() { return super.getPerimeter() * height; } public void show() { super.show(); // 调用父类的 show() 方法展示圆的基本信息 System.out.printf("圆柱高度:%.1f\n", height); System.out.printf("圆柱侧面积:%.3f\n", getSurface()); System.out.printf("圆柱体积:%.3f\n", getVolume()); } } ``` 在 Main 类中,可以修改为使用 Cylinder 类的 show() 方法来展示圆柱的信息: ``` public class Main { public static void main(String[] args) { Circle circle = new Circle(6); circle.show(); Cylinder cylinder = new Cylinder(8, 10); cylinder.show(); // 修改为使用 Cylinder 类的 show() 方法展示圆柱信息 } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值