小练习:
public class test1 {标签:int,System,month,ticket,seat,java9,out From: https://www.cnblogs.com/tqylqt/p/18182779
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入当前机票的原价");
int ticket = sc.nextInt();
System.out.println("请输入月份");
int month = sc.nextInt();
System.out.println("请输入当前购买的舱位 0 头等舱 1经济舱");
int seat = sc.nextInt();
if (month >= 5 && month <= 10){
ticket = getPrice(ticket,seat,0.9,0.85);
} else if ((month >= 1 && month <= 4) || (month >= 11 && month <= 12)) {
ticket = getPrice(ticket,seat,0.7,0.65);
}else {
System.out.println("键盘录入的数据不合法");
}
System.out.println(ticket);
}
public static int getPrice(int ticket,int seat,double v0, double v1){
if (seat == 0){
ticket = (int) (ticket * v0);
}else {
ticket = (int) (ticket*v1);
}
return ticket;
}
}
条件if语句,用方法包装。