我有一个向量:
p[0]=0.40816269
p[1]=0.37576407
p[2]=0.16324950
p[3]=0.05282373
我需要将向量的值打印为 4 位小数的百分比。我试过:
for(int i=0; i<p.length;i++)
{
System.out.printf("Criterion "+i+" has the weigth=%.4f \n" , p[i]*100);
}
这给了我:
Criterion 0 has the weigth=40.8163, .....
但我想打印:
Criterion 0 has the weigth=40.8163 %, .....
我不能在每行的末尾添加符号“%”。如果我尝试:
System.out.printf("Criterion "+i+" has the weigth=%.4f %\n" , p[i]*100);
或者:
System.out.printf("Criterion "+i+" has the weigth=%.4f "+"%\n" , p[i]*100);
程序抛出异常。先感谢您!