gpt4 book ai didi

Java:我的编译器说我的 printf 语句之一已损坏,我不明白为什么

转载 作者:行者123 更新时间:2023-12-02 08:54:28 24 4
gpt4 key购买 nike

这是我第一次提问,如果这看起来很奇怪,很抱歉。这是我的完整代码。带星号的分隔线是断开的线。

import java.util.Scanner;
public class CashRegister
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double price;
final double TAX_RATE = 0.085;
final double SURCHARGE = 0.04;
final int MAX_PRICE = 500;
double addedSurcharge = 0;
do
{
do
{
System.out.print("Cost of Item (enter 0 or negative value to exit; max is $500.00): ");
price = keyboard.nextDouble();
} while (price > 500);
int dollars = (int) price;
int cents = (int) price - dollars;
int convertPrice = (dollars * 100) + cents;
if (convertPrice < 1500)
{
addedSurcharge = (convertPrice * SURCHARGE) / 100;
System.out.printf("Surcharge of $%.2f added.", addedSurcharge);
System.out.println();
}
double withTax = ((convertPrice * TAX_RATE) / 100) + addedSurcharge + convertPrice;

**System.out.printf("Amount due (with 8.5% tax): $%.2f", withTax);**

System.out.println();
} while (price > 0);
System.out.println("Done.");
}

最佳答案

您需要转义用作百分号的百分号:8.5%% 而不是 8.5%

关于Java:我的编译器说我的 printf 语句之一已损坏,我不明白为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60570564/

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