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

20150908 题目:判断某一天是这一年的第多少天

时间:2015-10-08 14:26:13      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

题目:判断某一天是这一年的第多少天

 

  static void Main(string[] args)

        {

            while (true)//循环

            {

                Console.Write("输入年:");

                int year = int.Parse(Console.ReadLine());

                Console.Write("输入月:");

                int month = int.Parse(Console.ReadLine());

                Console.Write("输入日:");

                int day = int.Parse(Console.ReadLine());

 

 

                bool isok = false;//用来记录日期是否正确

                bool isrun = false;

 

                if (year >= 1759 && year < 9999)

                {

                    if (month >= 1 && month <= 12)

                    {

                        if (month == 2)

                        {

                            if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))

//判断闰年能被400整除或者能被4整除同时不能被100整除

                            {

                                if (day >= 1 && day <= 29)

                                {

                                    isok = true;

                                    isrun = true;

                                }

                                else

                                {

                                    Console.WriteLine("应在29天范围之内");

                                }

                            }

                            else

                            {

                                if (day >= 1 && day <= 28)

                                {

                                    isok = true;

                                }

                                else

                                {

                                    Console.WriteLine("应在28天范围之内");

                                }

                            }

                        }

                        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)

                        {

                            if (day >= 1 && day <= 31)

                            {

                                isok = true;

                            }

                            else

                            {

                                Console.WriteLine("日期应在31天之内");

                            }

                        }

 

                        if (month == 4 || month == 6 || month == 9 || month == 11)

                        {

                            if (day >= 1 && day <= 30)

                            {

                                isok = true;

                            }

                            else

                            {

                                Console.WriteLine("日期应在30天之内");

                            }

                        }

                    }

                    else

                    {

                        Console.WriteLine("月份不正确");

                    }

                }

                else

                {

                    Console.WriteLine("年份不正确");

                }

 

 

                int sumday = 0;//第多少天

                if (isok)//日期正确,计算天数

                {

                    if (isrun)//是闰年

                    {

                        if (month == 1)

                        {

                            sumday = day;

                        }

                        if (month == 2)

                        {

                            sumday = 31 + day;

                        }

                        if (month == 3)

                        {

                            sumday = 31 + 29 + day;

                        }

                        if (month == 4)

                        {

                            sumday = 31 + 29 + 31 + day;

                        }

                        if (month == 5)

                        {

                            sumday = 31 + 29 + 31 + 30 + day;

                        }

                        if (month == 6)

                        {

                            sumday = 31 + 29 + 31 + 30 + 31 + day;

                        }

                        if (month == 7)

                        {

                            sumday = 31 + 29 + 31 + 30 + 31 + 30 + day;

                        }

                        if (month == 8)

                        {

                            sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + day;

                        }

                        if (month == 9)

                        {

                            sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + day;

                        }

                        if (month == 10)

                        {

                            sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;

                        }

                        if (month == 11)

                        {

                            sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;

                        }

                        if (month == 12)

                        {

                            sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;

                        }

                    }

                    else

                    {

                        if (month == 1)

                        {

                            sumday = day;

                        }

                        if (month == 2)

                        {

                            sumday = 31 + day;

                        }

                        if (month == 3)

                        {

                            sumday = 31 + 28 + day;

                        }

                        if (month == 4)

                        {

                            sumday = 31 + 28 + 31 + day;

                        }

                        if (month == 5)

                        {

                            sumday = 31 + 28 + 31 + 30 + day;

                        }

                        if (month == 6)

                        {

                            sumday = 31 + 28 + 31 + 30 + 31 + day;

                        }

                        if (month == 7)

                        {

                            sumday = 31 + 28 + 31 + 30 + 31 + 30 + day;

                        }

                        if (month == 8)

                        {

                            sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + day;

                        }

                        if (month == 9)

                        {

                            sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + day;

                        }

                        if (month == 10)

                        {

                            sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;

                        }

                        if (month == 11)

                        {

                            sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;

                        }

                        if (month == 12)

                        {

                            sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;

                        }

                    }

 

 

                    Console.WriteLine("第{0}天", sumday);

 

                }

                else

                {

                    Console.WriteLine("已经日期不正确,算不出来!");

                }

               

                Console.ReadLine();

            }

        }

20150908 题目:判断某一天是这一年的第多少天

标签:

原文地址:http://www.cnblogs.com/mn-b/p/4860686.html

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