题目:输入某年某月某日,判断这一天是这一年的第几天?
先给大家科普一下:
闰年是公历中的名词。闰年分为普通闰年和世纪闰年。
普通闰年:公历年份是4的倍数的,且不是100的倍数,为闰年。(如2004年就是闰年);
世纪闰年:公历年份是整百数的,必须是400的倍数才是世纪闰年(如1900年不是世纪闰年,2000年是世纪闰年);
公历中只分闰年和平年,平年有365天,而闰年有366天(2月中多一天)
package cn.ls.lanqiao;
import java.util.*;
public class Test14 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请分别输入所要查询的年月日:");
int year = sc.nextInt();
int month = sc.nextInt();
int days = sc.nextInt();
int[] list = { 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
int count = 0;
if (month == 1) {
count = days;
}
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
if (month > 1 && month < 13) {
count = list[month - 2] + days;
}
} else {
if (month > 1 && month < 13) {
count = list[month - 2] + days - 1;
}
}
System.out.print("这是该年的第" + count + "天");
}
}