第四章 第4题

时间:2022-09-01 20:41:12
Scanner input = new Scanner(System.in);
  int benjin=5000;
  System.out.println("请输入您出行月份:1~12");
  int yuefen = input.nextInt();
  System.out.println("请输入您选择头等舱还是经济舱?头等舱输入1经济舱输入2");
  double cang =input.nextDouble();
  switch (yuefen*10) {
  case 40:
  case 50:
  case 60:
  case 70:
  case 80:
  case 90:
  case 100:
   if (cang==1) {
   double jiage =benjin*0.9;
   System.out.println("您的机票价格为:"+jiage);
   }else if (cang==2) {
    double jiage=benjin*0.8;
    System.out.println("您的机票价格为:"+jiage);
   }
   break;
  case 10:
  case 20:
  case 30:
  case 110:
  case 120:
   if (cang==1) {
    double jiage=benjin*0.5;
    System.out.println("您的机票价格为:"+jiage);
   }else {
    if (cang==2) {
     double jiage=benjin*0.4;
     System.out.println("您的机票价格为:"+jiage);
    }
   }
   break;
  default:
   System.out.println("请输入正确数字");
   break;