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

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                 while (true)
                {
                    Console.Write("请输入年份:");
                    int year = int.Parse(Console.ReadLine());
                    Console.Write("请输入月份:");
                    int yue = int.Parse(Console.ReadLine());
                    Console.Write("请输入日期:");
                    int riqi = int.Parse(Console.ReadLine());
    
                    if (year > 0 && year < 9999)
                    {
                        if (yue == 1 || yue == 3 || yue == 5 || yue == 7 || yue == 8 || yue == 10 || yue == 12)
                        {
                            if (riqi > 0 && riqi <= 31)
                            {
                                Console.WriteLine("你输入的日期正确,请继续努力!");
                            }
                            else
                            {
                                Console.WriteLine("请输入正确的日期,谢谢。");
                            }
                        }
                        else if (yue == 4 || yue == 6 || yue == 9 || yue == 11)
                        {
                            if (riqi > 0 && riqi <= 30)
                            {
                                Console.WriteLine("你输入的日期正确,请继续努力!");
                            }
                            else
                            {
                                Console.WriteLine("请输入正确的日期,谢谢。");
                            }
                        }
                        else if (yue == 2)
                        {
                            if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
                            {
                                if (riqi > 0 && riqi <= 29)
                                {
                                    Console.WriteLine("你输入的日期正确,请继续努力");
                                }
                                else
                                {
                                    Console.WriteLine("请输入正确的日期,谢谢。");
                                }
                            }
                            else
                            {
                                if (riqi > 0 && riqi <= 28)
                                {
                                    Console.WriteLine("你输入的日期正确,请继续努力");
                                }
                                else
                                {
                                    Console.WriteLine("请输入正确的日期,谢谢。");
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("请输入正确的日期,谢谢。");
                        }
                    }
                    else
                    {
                        Console.WriteLine("请输入正确的日期,谢谢。");
                    }
                    Console.ReadLine();
                }
            }
        }
    }
  • 相关阅读:
    Java-io流入门到精通详细总结
    Java网络编程总结
    递归--逆波兰表达式
    递归--N皇后问题
    递归--汉诺塔问题 (Hanoi)
    递归--求n!的阶乘结果
    枚举--熄灯问题
    枚举--假币问题
    枚举--生理周期
    枚举--完美立方Python算法实现
  • 原文地址:https://www.cnblogs.com/qixinjian/p/4586026.html
Copyright © 2011-2022 走看看