• 判断年月日是否正确



    //输入年月日
    Console.Write("请输入年:");
    int year = Convert.ToInt32(Console.ReadLine());
    Console.Write("请输入月:");
    int month = Convert.ToInt32(Console.ReadLine());
    Console.Write("请输入日:");
    int day = Convert.ToInt32(Console.ReadLine());


    if ((year % 4 == 0 && year % 100 != 0) || (year % 100 == 0 && year % 400 == 0))
    {
    if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
    {

    if (day >= 1 && day <= 31)
    {
    Console.WriteLine("正确");
    }
    else
    {
    Console.WriteLine("错误");
    }


    }

    else if (month == 4 || month == 6 || month == 9 || month == 11)
    {
    if (day >= 1 && day <= 30)
    {
    Console.WriteLine("正确");

    }
    else
    {
    Console.WriteLine("错误");
    }

    }

    else
    {
    if (day >= 1 && day <= 29)
    {
    Console.WriteLine("正确");
    }
    else
    {

    Console.WriteLine("错误");
    }

    }


    }

    else
    {
    if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
    {
    if (day >= 1 && day <= 31)
    {
    Console.WriteLine("正确");

    }
    else
    {
    Console.WriteLine("错误");
    }


    }

    else if (month == 4 || month == 6 || month == 9 || month == 11)
    {
    if (day >= 1 && day <= 30)
    {
    Console.WriteLine("正确");

    }
    else
    {
    Console.WriteLine("错误");
    }


    }

    else
    {
    if (day >= 1 && day <= 28)
    {
    Console.WriteLine("正确");

    }
    else
    {
    Console.WriteLine("错误");

    }

    }

    }

    Console.ReadLine();

  • 相关阅读:
    A1091. Acute Stroke
    A1103. Integer Factorization
    A1097. Deduplication on a Linked List
    A1074. Reversing Linked List
    设计模式之装饰模式
    基于UML的需求分析和系统设计
    软件测试开篇
    当抽象类遇到单例模式
    设计模式开篇
    此刻开始,点滴积累
  • 原文地址:https://www.cnblogs.com/weixiaofantasy/p/4546553.html
Copyright © 2020-2023  润新知