第一个JAVA程序,输入年份,判断该年份是否为闰年



下面展示 JAVA代码

import java.util.Scanner;
public class Test {
	public static void main(String[] args) {
		//定义变量year
		int year;
		//键盘输入
		Scanner sc = new Scanner(System.in);
		year = sc.nextInt();
		sc.close();
		//判断是否为闰年
			if((year % 4 == 0 && year % 100 !=0) || year % 400 == 0) {
				//如果年份很大,被3200整除还要判断是否能被172800整除
				if(year % 3200 == 0 && year % 172800 != 0) {
					System.out.println(year + " is  not a leapyear ");
				}
				else 
					System.out.println(year + " is   a leapyear ");
			}	
			else
				System.out.println(year + " is not a leapyear");
			
	}
}

更多推荐

用JAVA程序判断是否为闰年(代码)