天天看点

java实现2000年到3000年之间的所有闰年

判断是不是闰年 2000–3000

package com.shipeiqi.yingyong;

public class ClassP6 {

	static int LeapYear(int year){
		if((year%400 == 0) || (year%100!=0)&& (year%4==0)){
			return 1;   //是闰年,则返回1
		}else{
			return 0;	//不是闰年,则返回0
		}
	}
	public static void main(String[] args) {
		int year;
		int count = 0;
		System.out.println("2000年到3000年");
		for(year = 2000;year<=3000;year++){
			if(LeapYear(year) == 1){
				System.out.println(year+"");
				count++;
				if(count%16 == 0){
					System.out.print("\n");
				}
			}
		}
		System.out.print("\n");
	}
}