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

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闰年的数量为:"+闰年数量);
 }

}

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