java机票订购两种方法 关键代码

    xiaoxiao2022-06-30  64

    <span style="font-size:18px;">Scanner input=new Scanner(System.in); System.out.println("请输入你出行的月份:1~12"); int jiage=5000; int yue =input.nextInt(); System.out.println("请问你选择头等舱还是普通舱?头等舱(头等舱输入1普通舱输入2)"); int cang=input.nextInt(); if (yue>=4&&yue<=10){ if(cang==1){ System.out.println("你的机票价格是:"+jiage*0.9); }else if(cang==2){ System.out.println("你的机票价格是:"+jiage*0.8); } }else { if(cang==1){ System.out.println("你的机票价格是:"+jiage*0.5); }else if(cang==2){ System.out.println("你的机票价格是:"+jiage*0.4); } } ******************************************************************************************** Scanner input = new Scanner(System.in); int jia = 5000; int yue; int cang; System.out.println("请输入您出行的月份:1~12"); yue = input.nextInt(); System.out.println("请问您选择头等舱还是经济舱?头等舱输入1,经济舱输入2"); cang = input.nextInt(); switch (yue % 10) { case 1: case 2: case 3: if (cang == 1) { System.out.println("您的机票价格为:" + jia * 0.9); } else if (cang == 2) { System.out.println("您的机票价格为:" + jia * 0.8); } break; case 0: case 4: case 5: case 6: case 7: case 8: case 9: if (cang == 1) { System.out.println("您的机票价格为:" + jia * 0.5); } else if (cang == 2) { System.out.println("您的机票价格为:" + jia * 0.4); } break; default: System.out.println("输入错误"); break; }</span>
    转载请注明原文地址: https://ju.6miu.com/read-1125873.html

    最新回复(0)