2018-11-07

2018-11-07  本文已影响0人  一只皮皮橙

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication4

{

    class Program

    {

        static void Main(string[] args)

        {

                //请用户输年份,再输入月份,输出该月的天数.

                Console.WriteLine("请用户输入年份");

                string str_year = Console.ReadLine();

                int year = Convert.ToInt32(str_year);

                Console.WriteLine("请用户输入月份");

                string str_month = Console.ReadLine();

                int month = Convert.ToInt32(str_month);

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

                {

                    int day = 0;

                    switch (month)

                    {

                        case 1:

                        case 3:

                        case 5:

                        case 7:

                        case 8:

                        case 10:

                        case 12:

                            day = 31;

                            break;

                        case 2:

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

                            {

                                day = 29;

                            }

                            else

                            {

                                day = 28;

                            }

                            break;

                        default:

                            day = 30;

                            break;

                    }//swich

                    Console.WriteLine("{0}年{1}月有{2}天", year, month, day);

                }//if

                else

                {

                    Console.WriteLine("月份必须在1~12月之间,程序退出!!!");

                }

            Console.ReadKey();

            } 

        }

    }

上一篇下一篇

猜你喜欢

热点阅读