码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-05-18 22:45:59      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:

//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;
            }

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

标签:

原文地址:http://www.cnblogs.com/wordgao/p/4513102.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!