输入某年某月某日,判断这一天是这一年的第几天 Java
时间: 2023-11-20 13:58:14 浏览: 68
以下是Java实现输入某年某月某日,判断这一天是这一年的第几天的代码:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入年份:");
int year = scanner.nextInt();
System.out.print("请输入月份:");
int month = scanner.nextInt();
System.out.print("请输入日期:"); int day = scanner.nextInt();
int sum = 0;
int[] days = {31,28,31,30,31,30,31,31,30,31,30,31};
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
days[1] = 29;
}
for (int i = 0; i < month - 1; i++) {
sum += days[i];
}
sum += day;
System.out.println(year + "年" + month + "月" + day + "日是这一年的第" + sum + "天。");
}
}
```
阅读全文