tags:

views:

83

answers:

2

I am new to programming so I apologize beforehand. I am running a program and am having a problem with the System.out.printf method in Java. I know everything else in the program is working correctly (tested it). However this does not seem to work.

The error is:

Exception in thread "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.printf(Unknown Source)
at Advisor_Score.main(Advisor_Score.java:17)

My code is:

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]);
                }       
    }
}

Not really sure why it's not working.

+6  A: 

%d represents an integer; you want to use %f for a double. See the formatting string syntax in the Javadoc

Michael Mrozek
A: 

For quick fix you could always use System.Out.println() to avoid format errors :D

Chris