zoukankan      html  css  js  c++  java
  • 练习!!年月日判断并输出第多少天

    while (true) //输入年月日判断是该年的第几天
    {
    int year, mooth, day;
    Console.Write("请输入年份:");
    year=int.Parse( Console.ReadLine());
    if ((year > 1759 && year <= 9999) && (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)))
    {
    Console.Write("请输入月份;");
    mooth = int.Parse(Console.ReadLine());
    if (mooth >= 1 && mooth <= 12)
    {
    Console.Write("请输入日期:");
    day = int.Parse(Console.ReadLine());
    int m1=31, m2=28,m3=31, m4=30, m5=31, m6=30, m7=31, m8=31, m9=30, m10=31, m11=30;
    if(mooth==1&&(day>=1&&day<=31))
    {
    Console.WriteLine("这是"+year+"第"+day+"天");
    }
    else if (mooth == 2 && (day >= 1 && day <= 28))
    {
    Console.WriteLine("这是" + year + "第" +(m1+day) + "天");
    }
    else if (mooth == 3 && (day >= 1 && day <= 31))
    {
    Console.WriteLine("这是" + year + "第" + (m1+m2+ day) + "天");
    }
    else if (mooth == 4 && (day >= 1 && day <= 30))
    {
    Console.WriteLine("这是" + year + "第" + (m1+m2+m3+ day) + "天");
    }
    else if (mooth == 5 && (day >= 1 && day <= 31))
    {
    Console.WriteLine("这是" + year + "第" + (m1+m2+m3+m4 + day) + "天");
    }
    else if (mooth == 6 && (day >= 1 && day <= 30))
    {
    Console.WriteLine("这是" + year + "第" + (m1+m2+m3+m4+m5 + day) + "天");
    }
    else if (mooth == 7 && (day >= 1 && day <= 31))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + m5+m6 + day) + "天");
    }
    else if (mooth == 8 && (day >= 1 && day <= 31))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + m5 + m6+m7 + day) + "天");
    }
    else if (mooth == 9 && (day >= 1 && day <= 30))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 +m8+ day) + "天");
    }
    else if (mooth == 10 && (day >= 1 && day <= 31))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8+m9 + day) + "天");
    }
    else if (mooth == 11 && (day >= 1 && day <= 30))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + m9+m10 + day) + "天");
    }
    else if (mooth == 12 && (day >= 1 && day <= 31))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + m9 + m10+m11 + day) + "天");
    }
    else
    {
    Console.WriteLine("输入日期有误");
    }
    }
    else
    {
    Console.WriteLine("输入月份有误");
    }

    }
    else if ((year > 1759 && year <= 9999) && !((year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))))
    {
    Console.Write("请输入月份;");
    mooth = int.Parse(Console.ReadLine());
    if (mooth >= 1 && mooth <= 12)
    {
    Console.Write("请输入日期:");
    day = int.Parse(Console.ReadLine());
    int m1 = 31, m2 = 29, m3 = 31, m4 = 30, m5 = 31, m6 = 30, m7 = 31, m8 = 31, m9 = 30, m10 = 31, m11 = 30;
    if (mooth == 1 && (day >= 1 && day <= 31))
    {
    Console.WriteLine("这是" + year + "第" + day + "天");
    }
    else if (mooth == 2 && (day >= 1 && day <= 28))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + day) + "天");
    }
    else if (mooth == 3 && (day >= 1 && day <= 31))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + day) + "天");
    }
    else if (mooth == 4 && (day >= 1 && day <= 30))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + day) + "天");
    }
    else if (mooth == 5 && (day >= 1 && day <= 31))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + day) + "天");
    }
    else if (mooth == 6 && (day >= 1 && day <= 30))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + m5 + day) + "天");
    }
    else if (mooth == 7 && (day >= 1 && day <= 31))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + m5 + m6 + day) + "天");
    }
    else if (mooth == 8 && (day >= 1 && day <= 31))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + day) + "天");
    }
    else if (mooth == 9 && (day >= 1 && day <= 30))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + day) + "天");
    }
    else if (mooth == 10 && (day >= 1 && day <= 31))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + m9 + day) + "天");
    }
    else if (mooth == 11 && (day >= 1 && day <= 30))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + m9 + m10 + day) + "天");
    }
    else if (mooth == 12 && (day >= 1 && day <= 31))
    {
    Console.WriteLine("这是" + year + "第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + m9 + m10 + m11 + day) + "天");
    }
    else
    {
    Console.WriteLine("输入日期有误");
    }
    }
    else
    {
    Console.WriteLine("输入月份有误");
    }
    }
    else
    {
    Console.WriteLine("输入年份有误");
    }

  • 相关阅读:
    G++与VS2015在变量作用域上的差异性
    SO_REUSEADDR与SO_REUSEPORT平台差异性与测试
    带着SMART原则重新出发
    动态语言的灵活性是把双刃剑 -- 以Python语言为例
    程序员必知的Python陷阱与缺陷列表
    MySQL添加字段和修改字段
    java poi给sheet表格中的某个单元格添加批注
    Maven入门:使用Nexus搭建Maven私服及上传下载jar包
    Linux上两种网络连接方式
    linux创建账户并自动生成主目录和主目录下的文件
  • 原文地址:https://www.cnblogs.com/lz123/p/4932228.html
Copyright © 2011-2022 走看看