定义一个变量,在每个case下赋值,最后return
public static int orderDishes(int choice) {
int price = 0;
switch (choice) {
case 1:
System.out.println("1. 青岛啤酒 8RMB");
price = 8;
break;
case 2:
System.out.println("2. 野格 88RMB");
price = 88;
break;
case 3:
System.out.println("3. 江小白 25RMB");
price = 25;
break;
case 4:
System.out.println("4. 乌苏 6RMB");
price = 6;
break;
case 5:
System.out.println("5. 1664 18RMB");
price = 18;
break;
}
return price;
}