日期:2014-05-20  浏览次数:20636 次

这题有点困难,求解啊
某人准备去海南旅游,现在要订机票。机票的价格受季节旺季、淡季的影响,头等舱和经济舱价格也不同。假设机票原价为5000元,4~10月为旺季,旺季头等舱打九折,经济舱打八折,淡季头等舱打五折,经济舱打四折。编写程序,使用嵌套if选择结构
------解决方案--------------------
import java.util.Scanner;

public class Test
{
public static void main(String[] args)
{
double old = 5000;
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();  //i代表月份
if (i <4)
{
if (i>0)
{
System.out.println("淡季:头等舱为" + old*0.5);
System.out.println("淡季:经济舱为" + old*0.4);
}
if (i<=0)
{
System.out.println("输入月份不正确");
}

}
if (i >= 4)
{

if (i < 11)
{
System.out.println("旺季:头等舱为" + old*0.9);
System.out.println("旺季:经济舱为" + old*0.8);
}
if (i >= 11)
{
if (i > 12)
{
System.out.println("输入月份不正确");
}
if (i <= 12)
{
System.out.println("淡季:头等舱为" + old*0.5);
System.out.println("淡季:经济舱为" + old*0.4);
}
}
}
}
}