注意:它只是一个基本的java程序,没有jframe等。
import java.io.*;
public class Case1 {
public static void main(String[] Ropher) throws IOException{
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
int t; int y;
System.out.print("Welcome To M.Y Hotel!");
System.out.println("\nPlease Select For Information");
System.out.println("1 --- Bed Menu");
System.out.println("2 --- Food Menu");
System.out.println("3 --- Exit");
System.out.println("");
t = Integer.parseInt(br.readLine());
switch (t){
case 1 :
System.out.println("1 --- Single Bed");
System.out.println("2 --- Double Bed");
System.out.println("3 --- Family Bed");
System.out.println("4 --- Social Bed");
break;
case 2:
System.out.println("1 --- Appetizer");
System.out.println("2 --- Soup");
System.out.println("3 --- Breakfast");
System.out.println("4 --- Lunch");
System.out.println("5 --- Dinner");
break;
}
System.out.println("Please Select");
y = Integer.parseInt(br.readLine());
switch (y){
case 1:
System.out.println("Single Beds: ");
System.out.println("Standard --- P750");
System.out.println("King Bed --- P1000");
System.out.println("Crystal Bed --- P1750");
System.out.println("Water Bed --- P2000");
case 2:
System.out.println("Double Beds: ");
System.out.println("Deluxe A --- P1000");
System.out.println("Deluxe B --- P1500");
System.out.println("Water Double Bed --- P3000");
}
}
}
如果我在switch(t)中选择案例2,我想制作一个跳过案例的程序,会弹出一些内容(例如开胃菜)该选项的信息并跳过开关中的案例(y)
答案 0 :(得分:0)
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = 0;
int y;
welcome(t, br);
System.out.println("Please Select");
y = Integer.parseInt(br.readLine());
switch (y) {
case 1:
System.out.println("Single Beds: ");
System.out.println("Standard --- P750");
System.out.println("King Bed --- P1000");
System.out.println("Crystal Bed --- P1750");
System.out.println("Water Bed --- P2000");
break;
case 2:
System.out.println("Double Beds: ");
System.out.println("Deluxe A --- P1000");
System.out.println("Deluxe B --- P1500");
System.out.println("Water Double Bed --- P3000");
break;
}
}
private static void welcome(int t, BufferedReader br) throws Exception {
System.out.print("Welcome To M.Y Hotel!");
System.out.println("\nPlease Select For Information");
System.out.println("1 --- Bed Menu");
System.out.println("2 --- Food Menu");
System.out.println("3 --- Exit");
System.out.println("");
t = Integer.parseInt(br.readLine());
switch (t) {
case 1:
System.out.println("1 --- Single Bed");
System.out.println("2 --- Double Bed");
System.out.println("3 --- Family Bed");
System.out.println("4 --- Social Bed");
break;
case 2:
welcome(t, br);
break;
}
}