當試圖從我的Account類打印信息時,它出現錯誤。爲什麼在使用printf時會出現運行時錯誤?
這裏是我的代碼:
System.out.printf("%5d $,9.2f %,5,2f%% %29s\n\n", account1.getId(), account1.getBalance(), account1.getAnnualInterestRate(), account1.getDateCreated());
和錯誤:
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = ','
at java.util.Formatter.checkText(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at TestAccount.printAccount(TestAccount.java:16)
at TestAccount.main(TestAccount.java:11)
感謝
它似乎在抱怨逗號。 – forgivenson
也許試試「%5d $,9.2f%,5.2f %%%29s \ n \ n」? – totoro
你想用'%,5,2f'實現什麼? – Pshemo