线程 "main" java.util.MissingFormatArgumentException 中的异常:格式说明符“.2f”?

Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '.2f'?

你能告诉我问题出在哪里吗?我在这里没有使用连接,错误仍然存​​在。

这里是 StackTrace:

`adding $Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '.2f'
at java.util.Formatter.format(Formatter.java:2487)
at java.io.PrintStream.format(PrintStream.java:970)
at java.io.PrintStream.printf(PrintStream.java:871)
at accounttest.main(accounttest.java:18)`

这是我正在谈论的代码:

import java.util.*;
import java.io.*; 
public class accounttest{

public static void main(String[] args) {
    account account1 = new account(50.00);
    account account2 = new account(-7.50);

    System.out.printf("account 1 balance: $%.2f\n", account1.getBalance());
    System.out.printf("account 2 balance: $%.2f\n", account2.getBalance());

    Scanner input = new Scanner(System.in);
    double depositAmount;

    System.out.printf("Enter deposit amount for account 1\n>>");
    depositAmount = input.nextDouble();
    System.out.printf("\nadding $%.2f to account 1 balance\n\n");
    account1.credit(depositAmount);

    //displaying the current amount in both of the accounts

    System.out.printf("account 1 balance: $%.2f\n", account1.getBalance());
    System.out.printf("account 2 balance: $%.2f\n", account2.getBalance());

    System.out.printf("Enter deposit amount for account 2\n>>");
    depositAmount = input.nextDouble();
    System.out.printf("\nadding $%.2f rupees to account 2 balance\n\n");
    account2.credit(depositAmount);

    System.out.printf("account 1 balance: $%.2f\n", account1.getBalance());
    System.out.printf("account 2 balance: $%.2f\n", account2.getBalance());

}
}

如堆栈跟踪所示,在缺少的地方添加一个格式参数,就像您在其他语句中所做的那样

System.out.printf("\nadding $%.2f to account 1 balance%n", depositAmount);
                                                           ^