A.2.5-输入年,月,判断本月有多少天?

ylbtech- .NET-Basic: A.2.5-输入年,月,判断本月有多少天?

A.2.5-输入年,月,判断本月有多少天?

//输入年,月
//定义函数判断一个年份是否为闰年
//定义函数,根据年份,月份,判断该月有多少天

1.A,源代码返回顶部
using System;

namespace Test2
{
    class Program
    {
        static void Main(string[] args)
        {
            //输入年,月
            //定义函数判断一个年份是否为闰年
            //定义函数,根据年份,月份,判断该月有多少天
            Console.WriteLine("请输入年份?");
            int year = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入月份?");
            int month =Convert.ToInt32( Console.ReadLine());
            //逻辑运算符
            //&& 且
            //|| 或
            if (month == 2)
            {
                if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
                {
                    Console.WriteLine("29");
                }
                else
                {
                    Console.WriteLine("28");
                }
            }
            else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
            {
                Console.WriteLine("30");
            }
            else
            {
                Console.WriteLine("31");
            }
            Console.ReadLine();
        }
    }
}
warn 作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
posted on 2013-03-24 23:25  ylbtech  阅读(547)  评论(0编辑  收藏  举报