gpt4 book ai didi

java - 线程 "main"java.util.UnknownFormatConversionException : Conversion = ' ' 中的异常

转载 作者:行者123 更新时间:2023-12-01 14:03:33 26 4
gpt4 key购买 nike

<分区>

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 的金额时会出现此错误。我应该怎么做??

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com