Java输入一个整数年份,要求判断是否是闰年。判断条件:能被四整除但是不能被100整除,能被四百整除。

import java.util.Scanner;

public class Test07 {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    System.out.println("请输入年份: ");
		int year = sc.nextInt();
		if(year % 4 ==0 && year % 100 !=0 || year % 400 ==0) {
			System.out.println(year + "年是闰年");
		}else {
			System.out.println(year +"年是平年");
		}
	}
}

 


版权声明:本文为xuexizhengqian原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。