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 + "天"); } } }
题目:输入某年某月某日,判断这一天是这一年的第几天?
最新推荐文章于 2022-12-20 09:05:53 发布