java的printf和c,printf的:在Java的和C的实现差异

博客讨论了Java和C语言中printf函数在处理宽度和精度参数时的不同。在C语言中,`%*d`, `%-*d`, `%0*d`, `%*.5f`, `%-11.*f`, `%0*.*f`等格式化字符串是有效的,但Java不支持这种用法。建议详细阅读Java文档以了解两者间的差异。
摘要由CSDN通过智能技术生成

I noticed today that I can't use * to pass width or precision arguments to Java's implementation of printf.

That is, the following arguments to printf are valid in C, but not Java:

"%*d", 10, 3

"%-*d", 10, 3

"%0*d", 10, 3

"%*.5f", 11, 1.0/9

"%-11.*f", 5, 1.0/9

"%0*.*f", 11, 5, 1.0/9

Are there any other implementation differences I should be aware of?

解决方案

I wouldn't think of it as differences. I'd just read through the Java documentation carefully and go entirely from that. Thinking in terms of differences is likely to lead to things slipping through the net.

In other words, I'd treat the similarities as coincidences, and assume the two are different until proven otherwise :)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值