【发布时间】:2016-02-15 18:48:43
【问题描述】:
考虑以下循环来打印图表: 假设数组中的所有元素以及感兴趣的元素都有一个赋值,为什么 for 循环(确切地说是 System.out.format)会产生 IllegalFormatPrecisionException?
double[] sbalance;
double[] fbalance;
double[] interest;
sbalance = new double[months];
fbalance = new double[months];
interest = new double[months];
int deposit;
for (int q = 1; q <= months; q++)
{
System.out.format ("%18.2d%", sbalance[q-1]);
System.out.format ("%18.2d%", interest [q-1]);
System.out.format ("%18.2d%", (double)deposit);
System.out.format ("%18.2d%", fbalance [q-1]);
}
即使我返回并将我的数组重新声明为 Double[] 而不是 double[],程序也会产生相同的错误(我意识到 java 在自动装箱方面不一致)
非常感谢任何帮助。
【问题讨论】:
标签: java formatting number-formatting