简体   繁体   中英

Java: printf is not applicable for the arguments (String, double)

I'm trying to compile code that I know to be working on other peoples' machines but is throwing a particular error on my system. Specifically the error relates to the printf() method

The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, double)

For instance

public static void main(String[] args) {

        double rate =10.5;
        System.out.printf("%.3f",  rate);
    }

Does anyone know why this error is cropping up? There are alternatives to using printf(), but this is very annoying!

您是否可能拥有Java编译器遵从级别1.4?

The funny thing is that it compiles without problem on Java 7, and prints out

10.500

It probably uses autoboxing . But omitting the issue of autoboxing - as your method accepts only Objects , and not primitives , you need to use a wrapper Double .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM