import java.util.Scanner;
public class ZuoYe9 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入你想查询的年份");
int year = sc.nextInt();
System.out.println("请输入你想查询的月份");
int month = sc.nextInt();
System.out.println("请输入你想查询的日期");
int day = sc.nextInt();
int[] arr1 = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int[] arr2 = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sum = 0;
if ((year % 4 == 0 && year % 100 == 0) || year % 400 == 0) {
for (int i = 0; i <= arr1.length - 1; i++) {
if (i + 1 <= month) {
sum += arr1[i];
}
}
sum += day;
System.out.println("这是" + year + "年的第" + sum + "天");
} else {
for (int j = 0; j <= arr2.length - 1; j++) {
if (j + 1 <= month) {
sum += arr2[j];
}
}
sum += day;
System.out.println("这是" + year + "年的第" + sum + "天");
}
}
}
题目:输入某年某月某日,判断这一天是这一年的第几天?
最新推荐文章于 2024-10-30 22:25:46 发布
该程序接收用户输入的年份、月份和日期,根据年份判断是否为闰年,然后计算出输入日期是当年的第几天。闰年判断条件为能被4整除但不能被100整除,或者能被400整除。
721

被折叠的 条评论
为什么被折叠?



