0
对于这个代码如何在格式化整数时使用空格和符号标志?
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
标志对第三条语句正常工作,但是会为第四条语句引发异常? - 对于第二条语句,为什么
(
标志会覆盖+
标志的效果?为什么不是相反呢?