读书人

判断闰年的JAVA兑现方式

发布时间: 2012-08-07 14:54:48 作者: rapoo

判断闰年的JAVA实现方式

 package base;/* * 类名  LeapYear.java * 说明 判断闰年 * 创建日期 2011-3-9 * 作者  kobe * 版权  *** */public class LeapYear {public static void main(String[] args) {int year = 1804;System.out.print(isLeapYear(year) ? year + " is leap year" : year + " is not leap year");}/** * 判断年份是否为闰年 * 判断闰年的条件, 能被4整除同时不能被100整除,或者能被400整除 */public static boolean isLeapYear(int year) {boolean isLeapYear = false;if (year % 4 == 0 && year % 100 != 0) {isLeapYear = true;} else if (year % 400 == 0) {isLeapYear = true;}return isLeapYear;}}

读书人网 >其他相关

热点推荐