System.out.println("請輸入你出行的月份:1~12");int jp=5000;int yf=input.nextInt();if (!input.hasNextInt()){System.out.println("請輸入正確的數字");}switch (yf){case 4:case 5:case 6:case 7:case 8:case 9:case 10:System.out.println("請問你選擇頭等艙還是經濟艙?頭等艙輸入1,經濟艙輸入2");if (!input.hasNextInt()){System.out.println("請輸入正確的數字");}int xz=input.nextInt();if (xz==1){System.out.println("你的機票價格為:"+(jp*0.9));}else if (xz==2){System.out.println("你的機票價格為:"+(jp*0.8));}else{System.out.println("請輸入1~2中的其中一個數字");}break;case 1:case 2:case 3:case 11:case 12:break;輸入完月份后就不繼續執行下一步了.是不是case里面不能添加if結構?
請問在java中switch是不是不能添加if?為什么呢?
慕的地8271018
2022-01-06 07:07:51