C#判断某一年是 “平年”||“闰年”,一月有多少天。

判断某一年是 “平年”||“闰年”,一月有多少天。

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天```

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值