package com.njwb.homework;
import java.util.Scanner;
/**
* 判断闰年程序
* @author kiii
* @version 1.0
* */
public class LeapYear {
public static void main(String[] args) {
//闰年能被4整除,但不能被100整除;②能被400整除
int year = 0;
Scanner input = new Scanner(System.in);
System.out.println("输入年份:");
year = input.nextInt();
if ((year%4 == 0 && year%100 != 0) || year%400 == 0) {
System.out.println(year+"是闰年!");
}else {
System.out.println(year+"不是闰年!");
}
}
}
根据闰年年份能被4整除,但不能被100整除且能被400整除,通过取模运算判断出闰年与非闰年,如有出入,欢迎指正!!!