zoukankan      html  css  js  c++  java
  • 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/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    Android 4.0新增Space及GridLayout初谈
    phpweb文件上传下载
    文件上传下载
    php大文件上传
    word图片上传到服务器
    文件中心支持上传下载
    文件管理系统开源
    ueditor word图片上传
    web超大文件上传
    java大视频上传实现
  • 原文地址:https://www.cnblogs.com/ylbtech/p/2979927.html
Copyright © 2011-2022 走看看