栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

C# 判断是否为闰年

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C# 判断是否为闰年

C# 判断是否为闰年 关注我,带你了解C#的魅力
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 判断是否为闰年
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("输入一个年份,下面自动判断是否为闰年,如果输入1,默认退出");
            //首先需要了解  4年一闰,100年不闰,4百年闰。
            while (true)      //此处了解下就好,这是用来无限循环的,省的运行一次就退出了
            {
                int year = Convert.ToInt32(Console.ReadLine());      //cinsole.readline()输出类型为string,年是数字类型,因此需要强制转换
                if (year==1)
                {
                    Console.Write("再按一次回车退出");
                    break;
                    
                }
                else
                {
                    if (year % 4 == 0)
                    {
                        if (year % 100 == 0)                       //   此处的%不是代表百分数,而是C#内的除余      除100看是否余0
                        {
                            if (year % 400 == 0)
                            {
                                Console.WriteLine("是闰年");
                            }
                            else
                            {
                                Console.WriteLine("不是闰年");
                            }
                        }
                        else
                        {
                            Console.WriteLine("是闰年");
                        }
                    }
                    else
                    {
                        Console.WriteLine("不是闰年");
                    }

                }

            }

            Console.ReadLine();
        }
    }
}

运行结果:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/911258.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号