首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

判断是不是是闰年

2012-09-04 
判断是否是闰年Check the year whether it is a Leap Year.import java.util.Calendarimport java.util.G

判断是否是闰年
Check the year whether it is a Leap Year.

import java.util.Calendar;import java.util.GregorianCalendar;import java.util.Scanner;/* * Check the year whether it is a leap year */public class LeapTest {public static void main(String[] agrs) {LeapTest test = new LeapTest();Scanner scanner = new Scanner(System.in);int year= Integer.parseInt(scanner.next());System.out.println("Year : "+year);System.out.println("Method1");if(test.checkLeapYear1(year)){System.out.println(year+" is a Leap Year!");}else{System.out.println(year+" is not a Leap Year!");}System.out.println("Method2");if(test.checkLeapYear2(year)){System.out.println(year+" is a Leap Year!");}else{System.out.println(year+" is not a Leap Year!");}}boolean checkLeapYear1(int year){Calendar cal = Calendar.getInstance();Boolean booleanLeapYear = ((GregorianCalendar) cal).isLeapYear(year);return booleanLeapYear;}boolean checkLeapYear2(int year){Boolean booleanLeapYear=false;if((year%4==0&&year%100==0)||(year%400==0)){booleanLeapYear=true;}return booleanLeapYear;}}

热点排行