0

我直接从书中复制代码,它不起作用。我无法弄清楚错误是什么。

Scanner input = new Scanner(System.in);
double depositAmount;
System.out.print("Enter deposit amount for account1: ");
depositAmount = input.nextDouble();
System.out.printf("\nadding %.2f to account1 balance\n\n", depositAmount);
account1.credit(depositAmount);

输出

run:
account1 balance: $50.00
account2 balance: $0.00

Enter deposit amount for account1: 25.50

adding $25.50 to account1 balance

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '.'
at java.util.Formatter.checkText(Formatter.java:2547)
at java.util.Formatter.parse(Formatter.java:2533)
at java.util.Formatter.format(Formatter.java:2469)
at java.io.PrintStream.format(PrintStream.java:970)
at java.io.PrintStream.printf(PrintStream.java:871)
at account.Account.main(Account.java:50)

Java Result: 1
BUILD SUCCESSFUL (total time: 6 seconds)
4

0 回答 0