JAVA课程设计天数计算器(输入年月日等到是当年的第几天)Would文档

小梅0429 2021-09-18 16:36 207 次浏览 赞 149

最新问答

  • 孤星泪新民

    // 你试试这个能不能实现
    import java.io.*;

    public class DateCal {
    static public void main(String[] args) {
    int year, month, day;
    int days = 0;
    boolean luinian = false;
    System.out.print("input the year:");
    year = IO.getInt();
    System.out.print("input the month:");
    month = IO.getInt();
    System.out.print("input the day:");
    day = IO.getInt();
    if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
    luinian = true;
    }
    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 2:
    days += 28;
    break;
    case 4:
    case 6:
    case 9:
    case 11:
    days += 30;
    break;
    }
    }
    if (luinian && month > 2) {
    days++;
    }
    days += day;
    System.out.println(year + "年" + month + "月" + day + "日是" + year + "的第"
    + days + "天");
    }
    }

    class IO {

    public static int getInt() {
    DataInputStream dis = new DataInputStream(System.in);
    int value = 0;
    try {
    @SuppressWarnings("deprecation")
    String str = dis.readLine();
    value = Integer.parseInt(str);

    } catch (IOException e) {
    e.printStackTrace();
    }
    return value;
    }
    }

    浏览 187赞 123时间 2024-02-21

JAVA课程设计天数计算器(输入年月日等到是当年的第几天)Would文档