switch case语句

  int yearDay = 0, monthDay = 0, days = 0;

            Console.WriteLine("请输入哪一年:");

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

            Console.WriteLine("请输入哪个月:");

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

            Console.WriteLine("请输入哪一天:");

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

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

            {

                yearDay = 366;

            }

            else

            {

                yearDay = 365;

            }

            for (int i = 1; i < month; i++)

            {

                switch (i)

                {

                    case 1:

                    case 3:

                    case 5:

                    case 7:

                    case 8:

                    case 10:

                    case 12:

                        monthDay = 31;

                        break;

                    case 4:

                    case 6:

                    case 9:

                    case 11:

                        monthDay = 30;

                        break;

                    case 2:

                        if (yearDay == 366)

                        {

                            monthDay = 29;

                        }

                        else

                        {

                            monthDay = 28;

                        }

                        break;

                    default:

                        Console.WriteLine("输入错误.......");

                        break;

                }

                days = days + monthDay;

            }

            days = days + day;

            Console.WriteLine("该日期是这一年的第{0}天", days);

你可能感兴趣的:(switch case语句)