电子灵魂

golang,go,C#,JAVA,PYTHON,PHP

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
//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;
            }
posted on 2015-05-18 21:21  conncent  阅读(2939)  评论(5编辑  收藏  举报