题目描述
输入 x,y(1582≤x<y≤3000)x,y(1582\le x < y \le 3000)x,y(1582≤x<y≤3000) ,输出 [x,y][x,y][x,y] 区间中闰年个数,并在下一行输出所有闰年年份数字,使用空格隔开。
输入格式
无
输出格式
无
输入输出样例
输入
1989 2001
输出
3
1992 1996 2000
import java.util.ArrayList;
import java.util.Scanner;
public class P5737 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
sc.close();
int count =0;
ArrayList arrayLists = new ArrayList();
for (int i = x; i <= y; i++) {
if (isLeapYear(i)){
count++;
arrayLists.add(i);
}
}
System.out.println(count);
for (int i = 0; i < arrayLists.size(); i++) {
System.out.print(arrayLists.get(i)+" ");
}
}
public static boolean isLeapYear(int a){
if ((a%400==0)||(a%4==0&&a%100!=0)){
return true;
}
else {
return false;
}
}
}