判断某一年是 “平年”||“闰年”,一月有多少天。
using System;
using System.Threading.Tasks.Sources;
namespace stars
{
class Program
{
static void Main(string[] args)
{
//for循环只是为了在控制台循环输出;
for (; ; )
{
//这是正式开始的源码;
//控制台输出年份和月份;
Console.WriteLine("输入年份?");
int year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("输入月份?");
int month = Convert.ToInt32(Console.ReadLine());
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
Console.WriteLine("{0}年,{1}月有31天", year, month);
break;
case 2:
if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0)
{
//判断闰年的2月有29天;
Console.WriteLine("{0}是闰年,2月有29天", year);
}
else
{
//判断平年的2月有28天;
Console.WriteLine("{0}是平年,2月有28天", year);
}
break;
default:
Console.WriteLine("{0}年,{1}月有30天", year, month);
break;
}
Console.ReadLine();
}
}
}
}
运行结果:
输入年份?
2012
输入月份?
2
2012是闰年,2月有29天
输入年份?
2020
输入月份?
2
2020是闰年,2月有29天
输入年份?
2021
输入月份?
2
2021是平年,2月有28天
输入年份?
2021
输入月份?
9
2021年,9月有30天
输入年份?
2021
输入月份?
8
2021年,8月有31天```