Java 从1970到20xx某一年中闰年的数量

来源:互联网 发布:人力资源大数据分析 编辑:程序博客网 时间:2024/05/16 00:25
public class LeapYear {  int 闰年数量 = 0/**  * 闰年的条件是:四年一闰,百年不闰,四百年再闰  * 1、能被4整除,但不能被100整除;  * 2、能被100整除,又能被400整除。  * 本文档以1970~2011年为例,可以自己更改  * @param year  * @return  */ public static boolean isLeapYear(int year){  return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ; } public static void main(String[] args) {  for(int i=1970; i<=2011; i++){   if(isLeapYear(i)){    System.out.println(""+i+"是闰年");    闰年数量++;   }  }    System.out.println("从1970~2011闰年的数量为:"+闰年数量); }}
0 0