zoukankan      html  css  js  c++  java
  • 判断年月日是否正确


    //输入年月日
    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();

  • 相关阅读:
    计算机网络 其他1
    C++ part9
    C++ part8
    操作系统 part5
    C++ part7
    MyXls导出Excel的各种设置
    C# excel操作
    Castle
    C# Keycode对照表
    IEnumerable.Select和SelectMany的区别
  • 原文地址:https://www.cnblogs.com/weixiaofantasy/p/4546553.html
Copyright © 2011-2022 走看看