话不多说放代码:
import java.util.Scanner;
public class Lx1 {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
menu();
}
public static void menu() {
System.out.println("请输入机票原价");//键盘输入机票的原始价格
double much = input.nextDouble();//定义double类型方便打折时计算小数
double MaxBestMuch = (much * 0.9);//商务舱旺季9折
double MaxMuch = (much * 0.85);//经济舱淡季85折
double MinBestMuch = (much * 0.7);//商务舱旺季7折
double MinMuch = (much * 0.65);//经济舱淡季65折
System.out.println("请输入月份");//键盘输入月份
int month = input.nextInt();
System.out.println("请选择头等舱或经济舱(1.头等舱--2.经济舱)");//键盘输入数字选择头等舱或经济舱
int num = input.nextInt();
if (num == 1) {
if (month > 10 && month < 13) {
System.out.println("价格是" + MinBestMuch);
}//判断11-12月份的价格并输出
if (month > 0 && month < 5) {
System.out.println("价格是" + MinBestMuch);
}//判断1-4月份的价格并输出
if (month > 4 && month < 11) {
System.out.println("价格是" + MaxBestMuch);
}//判断5-10月份的价格并输出
}
if (num == 2) {
if (month > 10 && month < 13) {
System.out.println("价格是" + MinMuch);
}//判断11-12月份的价格并输出
if (month > 0 && month < 5) {
System.out.println("价格是" + MinMuch);
}//判断1-4月份的价格并输出
if (month > 4 && month < 11) {
System.out.println("价格是" + MaxMuch);
}//判断5-10月份的价格并输出
}
}
}
运行截图: