运用if语句完成对年、月、日的判断。
Console.WriteLine("其输入年份:");
int a = int.Parse(Console.ReadLine());
Console.WriteLine("请输入月份:");
int yuefen = int.Parse(Console.ReadLine());
Console.WriteLine("请输入日期:");
int riqi = int.Parse(Console.ReadLine());
#region+闰年情况+
if ((a % 400 == 0 && a % 100 == 0) || (a % 4 == 0 && a % 100 != 0))
{
if (yuefen == 2)
{
if (riqi <= 29 && riqi > 0)
{
Console.WriteLine("这是闰年" + a + "年" + 2 + "月" + riqi + "号"+",是这一年的第{0}天",riqi +31);
}
else if (riqi > 29)
{
Console.WriteLine("闰年2月最大到29号,您输入的日期不正确!");
}
else
{
Console.WriteLine("您输入的日期不正确!");
}
}
else if (yuefen == 1 || yuefen == 3 || yuefen == 5 || yuefen == 7 || yuefen == 8 || yuefen == 10 || yuefen == 12)
{
if (riqi <= 31 && riqi > 0)
{
if (yuefen ==1)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号"+",是这一年的第{0}天",riqi );
}
else if (yuefen ==3)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号"+",是这一年的第{0}天",60+riqi );
}
else if (yuefen ==5)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号"+",是这一年的第{0}天",121+riqi );
}
else if (yuefen ==7)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号"+",是这一年的第{0}天",182+riqi );
}
else if (yuefen ==10)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号"+",是这一年的第{0}天",274+riqi );
}
else if (yuefen ==12)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号"+",是这一年的第{0}天",335+riqi );
}
}
else if (riqi > 31)
{
Console.WriteLine(a + "年这个月最大到31号。");
}
else
{
Console.WriteLine("您输入的日期不正确!");
}
}
else if (yuefen == 4 || yuefen == 6 || yuefen == 9 || yuefen == 11 )
{
if (riqi <= 30 && riqi > 0)
{
if (yuefen == 4)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", riqi+91);
}
else if (yuefen == 6)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", 152 + riqi);
}
else if (yuefen == 9)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", 244 + riqi);
}
else if (yuefen == 11)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", 300 + riqi);
}
}
else if (riqi > 30)
{
Console.WriteLine(a + "年这个月最大到31号。");
}
else
{
Console.WriteLine("您输入的日期不正确!");
}
}
else
Console.WriteLine("您输入的月份不正确!");
}
//+平年情况+
else
{
if (yuefen == 2)
{
if (riqi <= 28 && riqi > 0)
{
Console.WriteLine("这是平年" + a + "年" + 2 + "月" + riqi + "号" + ",是这一年的第{0}天", riqi + 31);
}
else if (riqi > 28)
{
Console.WriteLine("平年2月最大到28号,您输入的日期不正确!");
}
else
{
Console.WriteLine("您输入的日期不正确!");
}
}
else if (yuefen == 1 || yuefen == 3 || yuefen == 5 || yuefen == 7 || yuefen == 8 || yuefen == 10 || yuefen == 12)
{
if (riqi <= 31 && riqi > 0)
{
if (yuefen == 1)
{
Console.WriteLine("这是平年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", riqi);
}
else if (yuefen == 3)
{
Console.WriteLine("这是平年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", 59 + riqi);
}
else if (yuefen == 5)
{
Console.WriteLine("这是平年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", 120 + riqi);
}
else if (yuefen == 7)
{
Console.WriteLine("这是平年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", 181 + riqi);
}
else if (yuefen == 10)
{
Console.WriteLine("这是平年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", 273 + riqi);
}
else if (yuefen == 12)
{
Console.WriteLine("这是平年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", 334 + riqi);
}
}
else if (riqi > 31)
{
Console.WriteLine(a + "年这个月最大到31号。");
}
else
{
Console.WriteLine("您输入的日期不正确!");
}
}
else if (yuefen == 4 || yuefen == 6 || yuefen == 9 || yuefen == 11 )
{
if (riqi <= 30 && riqi > 0)
{
if (yuefen == 4)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", riqi + 90);
}
else if (yuefen == 6)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", 151 + riqi);
}
else if (yuefen == 9)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", 243 + riqi);
}
else if (yuefen == 11)
{
Console.WriteLine("这是闰年" + a + "年" + yuefen + "月" + riqi + "号" + ",是这一年的第{0}天", 299 + riqi);
}
}
else if (riqi > 30)
{
Console.WriteLine(a + "年这个月最大到31号。");
}
else
{
Console.WriteLine("您输入的日期不正确!");
}
}
else
Console.WriteLine("您输入的月份不正确!");
}
Console.ReadLine();