• Java编程——输入某年某月某日,判断这一天是这一年的第几天?



    package date;
    import java.util.*;

    public class Date {
      public static void main(String[] args) {
        int year, month, day;
        int days = 0;
        int d = 0;
        int e;
        input fymd = new input();
        do {
            e = 0;
            System.out.print("输入年:");
            year =fymd.input();
            System.out.print("输入月:");
            month = fymd.input();
            System.out.print("输入天:");
            day = fymd.input();
            if (year < 0 || month < 0 || month > 12 || day < 0 || day > 31)

            {
              System.out.println("输入错误,请重新输入!");
              e=1 ;
            }
           }while( e==1);
        for (int i=1; i <month; i++)

        {
          switch (i)

          {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:days = 31;break;
            case 4:
            case 6:
            case 9:
            case 11:days = 30;break;
            case 2:if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))

                {
                  days = 29;
                }

                else

                {
                  days = 28;
                }
                break;
              }
              d += days;
            }
            System.out.println(year + "-" + month + "-" + day + "是这年的第" + (d+day) + "天。");
          }
        }
    class input{
      public int input()

      {
        int value = 0;
        Scanner s = new Scanner(System.in);
        value = s.nextInt();
        return value;
      }
    }

     

  • 相关阅读:
    7. 初识Python之函数
    6. 初识Python之dict和set
    5. 初识Python之循环语句
    4. 初识Python之条件语句
    3. 初识Python之列表
    原生js实现一个小小的轮波
    原生js实现弹幕
    js实现一个简单的学生管理系统
    js绘制时钟
    js实现的学生管理系统
  • 原文地址:https://www.cnblogs.com/liao-pxsoftware15/p/7823499.html
Copyright © 2020-2023  润新知