Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“线程中的异常”;“主要”;java.util.MissingFormatArgumentException:格式说明符';。2f';?_Java_Format_Specifier - Fatal编程技术网

“线程中的异常”;“主要”;java.util.MissingFormatArgumentException:格式说明符';。2f';?

“线程中的异常”;“主要”;java.util.MissingFormatArgumentException:格式说明符';。2f';?,java,format,specifier,Java,Format,Specifier,你能告诉我哪里出了问题吗?我没有在这里使用连接,错误仍然存在 这是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) a

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

这是
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());

}
}

如stacktrace中所示,在缺少格式参数的地方添加一个格式参数,正如您在其他语句中所做的那样

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

请把你的问题格式化……我犯了个错误。这可能是我问过的最愚蠢的问题。谢谢,顺便说一句:D