class Restaurant {
static float Price;
static int quantity;
static float amount;
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
String order;
switch(order) {
case Starter:
quantity = sc.nextInt();
System.out.println("Do you want to add more item.");
Price = 2500;
amount = Price * quantity;
System.out.println(amount);
break;
case Main_Meal:
quantity = sc.nextInt();
System.out.println("Do you want to add more item ?");
Price = 2000;
amount = Price * quantity;
System.out.println(amount);
default:
System.out.println("No order");
}
}
}
答案 0 :(得分:3)
case Starter:
不是有效的switch语句表达式。开关“ case”中的字符串文字应加引号:
switch (order) {
case "Starter":
这在The switch Statement docs中有描述。