这是我第一次问一个问题,如果这看起来很奇怪,请抱歉。 这是我的完整代码。带有星号的分隔线是折线。
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.");
}
答案 0 :(得分:1)
您需要转义用作百分号的百分号:8.5%%
而不是8.5%