gpt4 book ai didi

compiler-errors - 餐厅计费程序连续出现错误

转载 作者:行者123 更新时间:2023-12-02 11:03:16 26 4
gpt4 key购买 nike

 import java.util.Scanner;
//This program computes tax and tip on a restaurant bill.

public class RestaurantBill
{
public static void main(String[] args) {


double charge;
double tax = 0.0675;
double tipRate = 0.15;
double totalWithTax;
double taxAmount;
double tipAmount;
double grandTotal;


Scanner keyboard = new Scanner(System.in);
System.out.print("What is your name? ");
name = keyboard.nextLine();
System.out.print("Please enter the cost of your meal ");
charge = keyboard.nextDouble();

System.out.println("Hi there " + name "\n Your tax is " + taxAmount " \n Your tip will be $" + tipAmount " /n and your total cost will be $" + grandTotal);
}
}

我一遍又一遍地得到这个错误...
  RestaurantBill2.java:24: error: ')' expected
System.out.println("Hi there " + name "\n Your tax is " + taxAmount " \n Your tip will be $" + tipAmount " /n and your total cost will be $" + grandTotal);

最佳答案

字符串连接中的语法错误:在错误消息中指示的行中,在+之后,name之后和taxAmount之后添加tipAmount

或将行分成几个单独的打印件:

System.out.println("Hi there " + name);
System.out.println("\n Your tax is " + taxAmount);
System.out.println("\n Your tip will be $" + tipAmount);
System.out.println("/n and your total cost will be $" + grandTotal);

使用带 ... lnt_rstrong后缀的函数时,检查是否真的需要打印\n

您可能还需要用/n替换\n并清理一些空格。
您当然也需要添加一些税费和小费计算...

关于compiler-errors - 餐厅计费程序连续出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28428841/

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