2
package com.supermarket.project;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        float amountF;
        Scanner amount = new Scanner(System.in);
        System.out.printf("Please enter the amount of purchase: ");
        amountF = amount.nextFloat();
        if (amountF >= 300) {
            System.out.printf("You amount of purchase is: %1.1f.%n"
                    + "You have a discount of: %1.1f * 90% = %1.1f.%n"
                    + "You can enjoy free delivery service.", amountF, amountF,
                    amountF * 0.9);
        } else {
            System.out.printf("Your amount of purchase is: %1.1f.%n"
                    + "Delivery service is available for additional $30.",
                    amountF);
        }
    }
}

然后我得到一个错误:

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = ' '
    at java.util.Formatter.checkText(Formatter.java:2547)
    at java.util.Formatter.parse(Formatter.java:2523)
    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 com.supermarket.project.Main.main(Main.java:11)

我应该怎么做才能纠正这个错误?帮助!!!当我输入的金额超过 300 但不低于 300 时,会出现此错误。我该怎么办??

4

1 回答 1

6

"You have a discount of: %1.1f * 90% = %1.1f.%n"

问题来自你的90%

将其更改为90%%

于 2013-05-04T03:40:01.817 回答