码迷,mamicode.com
首页 > 其他好文 > 详细

年月日判断程序

时间:2015-09-08 16:40:53      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

static void Main(string[] args)
        {
            while (true) //输入某年某月某日判断是该年第多少天
            {
                int year, mooth, day;
                Console.Write("请输入年份:");
                year=int.Parse( Console.ReadLine());
                if (year > 0 && year <= 9999)
                {
                    Console.Write("请输入月份:");
                    mooth = int.Parse(Console.ReadLine());
                    if (mooth >= 1 && mooth <= 12)
                    {
                        Console.Write("请输入日期:");
                        day = int.Parse(Console.ReadLine());
                        if((mooth==1||mooth==3||mooth==5||mooth==7||mooth==8||mooth==10||mooth==12)&&(day>=1 && day<=31))
                        {
                            Console.WriteLine("这是"+year+""+mooth+""+day+"");
                        }
                        else if ((mooth == 4 || mooth == 6 || mooth == 9 || mooth == 11) && (day >= 1 && day <= 30))
                        {
                            Console.WriteLine("这是" + year + "" + mooth + "" + day + "");
                        }
                        else if (mooth == 2 && (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) && (day >= 1 && day <= 29)) 
                        {
                            Console.WriteLine("这是" + year + "" + mooth + "" + day + "");
                        }
                        else if (mooth == 2 && (!(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))) && (day >= 1 && day <= 28))
                        {
                            Console.WriteLine("这是" + year + "" + mooth + "" + day + "");
                        }
                        else
                        {
                            Console.WriteLine("输入日期有误");
                        }
                    }
                    else 
                    {
                        Console.WriteLine("输入月有误");
                    }
                }

                else 
                {
                    Console.WriteLine("输入年有误");
                }

技术分享

年月日判断程序

标签:

原文地址:http://www.cnblogs.com/wang-kaifeng/p/4792178.html

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