1 package com.structure; 2 3 import java.util.Scanner; 4 5 public class ZuoYe03 { 6 7 public static void main(String[] args) { 8 Scanner meng00=new Scanner(System.in); 9 int ticket =5000; 10 System.out.println("请问您选择头等舱还是经济舱?头等舱输入1,经济舱输入2"); 11 int cang = meng00.nextInt(); //选择舱 12 System.out.println("请输入您出行的月份1~12"); 13 int yuefen=meng00.nextInt();//选择月份 14 while (yuefen>=1||yuefen<=12) {//1~12 15 System.out.println("请输入正确月份");//错误输入 16 yuefen=meng00.nextInt(); 17 } 18 19 20 if (cang==1) {//1头等舱 21 switch (yuefen) { 22 case 4: 23 case 5: 24 case 6: 25 case 7: 26 case 8: 27 case 9: 28 case 10: 29 System.out.println("你的机票价格为:"+ticket*0.9);//旺季 30 default: 31 System.out.println("你的机票价格为:"+ticket*0.5);//淡季 32 break; 33 } 34 }else if (cang==2) {//2经济舱 35 switch (yuefen) { 36 case 4: 37 case 5: 38 case 6: 39 case 7: 40 case 8: 41 case 9: 42 case 10: 43 System.out.println("你的机票价格为:"+ticket*0.8);//旺季 44 default: 45 System.out.println("你的机票价格为:"+ticket*0.4);//淡季 46 47 } 48 49 } 50 51 } 52 53 }