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


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM