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;
}
}