最近几天没有来逛站。偶然一看到自己的资料显示码龄4年。好尴尬啊。自己原来只是下载个文件注册了个账号。不过由于工作关系现在准备学习下这方面的知识 。不知道后期有没有多大的用途。但是总觉得老话说的好。技多不压身。能学习的时间和机会那就多多学习点儿东西。未来的事儿交给未来。现在有这个兴趣儿那就努力。
接下来是一道学习java中的练习题。今天当是自己给自己的考核。试试看能不能再写出来。
import java.util.Scanner;
public class Test01 {
//题目是:机票的价格按照淡旺季。分头等舱,和经济仓,输入机票的原价,月份和 头等舱和经济仓。按旺季 5-10月份 头等舱9折。经济舱8.5折,淡季11月到来年的4月。头等舱7折。经济舱6.5折。*、
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入您的机票原价");
int price = sc.nextInt();
System.out.println("请输入您的机票月份");
int month = sc.nextInt();
System.out.println("请输入您的机票的舱位。头等舱请输入0,经济舱请输入1");
int space = sc.nextInt();
if (month >= 5 && month <= 10) {
if (space == 0) {
price = (int) (price * 0.9);
} else if (space == 1) {
price = (int) (price * 0.85);
} else {
System.out.println("错误,您输入的舱位不存在");
}
} else if ((month >= 11 && month <= 12) || (month >= 1 && month <= 4)) {
if (space == 0) {
price = (int) (price * 0.7);
} else if (space == 1) {
price = (int) (price * 0.65);
} else {
System.out.println("错误,您输入的舱位不存在");
}
} else {
System.out.println("您的输入错误当前月份不存在");
}
System.out.println("您当前需要支付折扣后的价格为" + price);
}
}
其实这里是可以把嵌套内的判断。用定义一个方法的简写的。