餐厅结算程序持续出错

时间:2015-02-10 10:02:37

标签: compiler-errors

 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);

1 个答案:

答案 0 :(得分:0)

字符串连接中的语法错误:在+之后,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);

使用带 ... ln 后缀的功能时,请确认是否确实需要打印\n

您可能还想将/n替换为\n并清理一些空格 您当然还需要添加一些 tax tip 计算......