您的位置:首页 > 编程语言 > C#

C# 判断是否为闰年的条件各是

2015-05-18 21:21 447 查看
//try 没增加异常数据处理
Console.WriteLine("根据输入的信息计算当年某个月份的天数,以及当年是否是闰年或平年,\n并判断2月份特殊月份的天数。");
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("是31天");
break;
case 2:
if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0)
//闰年的判断条件格式
// 如果 年能被400整除 或者 年能被4整除 并且年不能被100整除。

{
Console.WriteLine("是闰年,2月当月的天数有29天");
}
else
{
Console.WriteLine("是平年,2月当月的天数有28天");
}
break;
default:
Console.WriteLine("为30天");
break;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐