Java 中的 System.out.printf 命令存在问题
我是编程新手,所以我事先道歉。我正在运行一个程序,并且Java中的方法有问题。我知道程序中的其他所有内容都正常工作(测试过)。然而,这似乎不起作用。System.out.printf
错误是:
线程 “main” java.util.IllegalFormatConversionException 中的异常: d != java.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.printInteger(Unknown Source)
at java.util.Formatter$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source) at java.io.PrintStream.format(Unknown Source)
atjava.io.PrintStream.printf(Unknown Source)
at Advisor_Score.main(Advisor_Score.java:17)
我的代码是:
import java.lang.Math;
public class Advisor_Score {
public static void main(String[] args){
double l[] = {101,1,1,1};
double k[] = {102,2,2,4};
double m[] = {103,5,5,5,5,5,5,5};
double All_users[][]={l,k,m};
double sum[]=new double [All_users.length];
double [] raw_advisor=new double [All_users.length];
double []advisor_score= new double [All_users.length];
for (int i=0;i<All_users.length;i++){
for(int j=1;j<All_users[i].length;j++){
sum[i]+=All_users[i][j];
}
raw_advisor[i]=((sum[i]-(3*(All_users[i].length-1)))/4);
advisor_score[i]= 2.5+(2.5*(1-Math.pow(Math.E, -.5*raw_advisor[i])));
System.out.printf("%d: %d\n", All_users[i][0], advisor_score[i]);
}
}
}
不太确定为什么它不起作用。