【发布时间】:2016-09-24 22:04:54
【问题描述】:
对于这个代码
public static void main(String[] args) {
System.out.println(String.format("%+(d", 14));
System.out.println(String.format("%+(d", -14));
System.out.println(String.format("% (d", 14));
System.out.println(String.format("%+ (d", -14));
}
输出是
+14
(14)
14
[An exception is thrown]
根据this page,正如标志部分所述,我可以使用+、(即空格)和(符号\标志来格式化整数,如下所示上面的代码。
我的问题是:
- 在哪里说明了这些标志如何相互交互?
- 为什么
space标志在第 3 条语句中工作正常,但在第 4 条语句中抛出异常? - 对于第二个语句,为什么
(标志会覆盖+标志的效果?为什么不是反过来?
【问题讨论】:
标签: java formatting