第六节课第二个作业

#编码

           /**

            *

            *  用户输年份,再输入月份,输出该月的天数

            * 

            * */

            Console.WriteLine("输年份");

            string str_year = Console.ReadLine();

            int year = Convert.ToInt32(str_year);

            Console.WriteLine("输月份");

            string str_months = Console.ReadLine();

            int months = Convert.ToInt32(str_months);

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

            {

                switch(months)

                {

                    case 1:

                Console.WriteLine("{0}年,{1}月,有31天",year,months);

                break;

                    case 3:

                Console.WriteLine("{0}年,{1}月,有31天", year, months);

                break;

                    case 4:

                Console.WriteLine("{0}年,{1}月,有30天", year, months);

                break;

                    case 5:

                Console.WriteLine("{0}年,{1}月,有31天", year, months);

                break;

                    case 6:

                Console.WriteLine("{0}年,{1}月,有30天", year, months);

                break;

                    case 7:

                Console.WriteLine("{0}年,{1}月,有31天", year, months);

                break;

                    case 8:

                Console.WriteLine("{0}年,{1}月,有31天", year, months);

                break;

                    case 9:

                Console.WriteLine("{0}年,{1}月,有30天", year, months);

                break;

                    case 10:

                Console.WriteLine("{0}年,{1}月,有31天", year, months);

                break;

                    case 11:

                Console.WriteLine("{0}年,{1}月,有30天", year, months);

                break;

                    case 2:

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

                {

                    Console.WriteLine("{0}年,{1}月,有29天", year, months);

                }

                else

                {

                    Console.WriteLine("{0}年,{1}月,有28天", year, months);

                }

                break;

                    default:

                Console.WriteLine("{0}年,{1}月,有31天", year, months);

                break;

                }

            }

            else

            {

                Console.WriteLine("月份在1~12之间");

            }

            Console.ReadKey();


Console.WriteLine("请输入一个年份");

int year = Convert.ToInt32(Console.ReadLine());

                       Console.WriteLine("请输入一个月份");

int month = Convert.ToInt32(Console.ReadLine());

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.WriteLine("请输入一个年份");

int year = Convert.ToInt32(Console.ReadLine());

                       Console.WriteLine("请输入一个月份");

int month = Convert.ToInt32(Console.ReadLine());

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.WriteLine("请输入一个年份");

int year = Convert.ToInt32(Console.ReadLine());

                       Console.WriteLine("请输入一个月份");

int month = Convert.ToInt32(Console.ReadLine());

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月之间,程序退出!!!")

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容