如何修复java代码中%s的“java.util.missingformatargumentexception:”

u4dcyp6a  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(185)

我正在为我的java类编写代码,当我将%s用于system.out.printf时,得到一个“java.util.missingformatargumentexception:”错误。
我试着把它都藏在“”标记里,试着分开。
这是我的密码:

System.out.println("your bill is: ");
        System.out.printf("%30s", "Item" + "%10s", "Quantity", "%-10s", "Price", "%-10s", "Total");
        System.out.printf("\n %s" + firstItem + "%10.2f" + firstItemQuant + "%10f" + firstItemPrice + "%10.2f" + firstItemTotal);
        System.out.printf("\n %s" + secondItem + "%10.2f" + secondItemQuant + "%10f" + secondItemPrice + "%10.2f" + secondItemTotal);
        System.out.printf("\n %s" + thirdItem + "10.2f" + thirdItemQuant + "%10f" + thirdItemPrice + "%10.2f" + thirdItemTotal);
        System.out.printf("\n %s -----------");
        System.out.printf("\n %s Subtotal %50f" + subtotal);

我得到的结果是:

your bill is: 
                      Item%10s
 Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '%s'
    at java.util.Formatter.format(Unknown Source)
    at java.io.PrintStream.format(Unknown Source)
    at java.io.PrintStream.printf(Unknown Source)
    at assignment1.main(assignment1.java:67)

我只想把账单格式化成几列

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题