输入某年某月某日,判断这一天是这一年的第几天?2020.6.14使用java语言递归方法实现
时间: 2023-11-20 20:55:01 浏览: 101
输入某年某月某日,判断这一天是这一年的第几天
4星 · 用户满意度95%
以下是使用Java语言递归方法实现输入某年某月某日,判断这一天是这一年的第几天的代码:
```java
public class DayOfYear {
private static int[][] days = {
{0,31,59,90,120,151,181,212,243,273,304,334},
{0,31,60,91,121,152,182,213,244,274,305,335}
};
public static int getDayOfYear(int year, int month, int day) {
int leap = 0;
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
leap = 1;
}
return days[leap][month - 1] + day;
}
public static void main(String[] args) {
int year = 2020;
int month = 6;
int day = 14;
int dayOfYear = getDayOfYear(year, month, day);
System.out.println(year + "年" + month + "月" + day + "日是这一年的第" + dayOfYear + "天");
}
}
```
阅读全文