计算从2000年到3000年之间的所有闰年(年份能被4整除,且不能被100整除,或者能被400整除的年份)
public class test {
public static void main(String[] args) {
for(year=2000;year<=3000;y++){
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
//为闰年
System.out.println(year+"为闰年");
}
}
}
}
for(int i=2000;i<=3000;i++)
{
if((i%4==0 && i%100 != 0) || (i%400 == 0))
System.out.println(i);
}
不要从2000循环到3000;直接从2000开始找到第一个闰年,然后由第一个闰年开始 +4 就行了