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");
}
}
}
case Starter:
不是有效的switch语句表达式。应引用交换机“case”中的字符串文字:
switch (order) {
case "Starter":
这在The switch Statement docs中有描述。