import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入年份:");
int year = input.nextInt();
System.out.print("请输入月份:");
int month = input.nextInt();
System.out.print("请输入日期:");
int day = input.nextInt();
// 计算是否为闰年
boolean isLeapYear = ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
// 定义月份的天数
int[] daysInMonth = {31, 28 + (isLeapYear ? 1 : 0), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// 计算这一天是该年的第几天
int dayOfYear = 0;
for (int i = 0; i < month - 1; i++) {
dayOfYear += daysInMonth[i];
}
dayOfYear += day;
System.out.println(year + "年" + month + "月" + day + "日是该年的第" + dayOfYear + "天。");
}
}
计算这一天是该年中第几天
于 2023-11-02 14:19:02 首次发布