import java.util.Scanner;
public class LeapYear{
public static void main(String[] args){
System.out.println("Please enter a year greater than 1582.");
Scanner scan=new Scanner(System.in);
int year=scan.nextInt();
int month=2,day=29;
if(year>=1582){
if(isLeapYear(year)){
System.out.println("\n"+year+" is leap year");
Zellers(year,month,day);
}
else{
System.out.println("\n"+year+" is not leap year");
}
}
else{
System.out.println("\nThe year that entered is out of range.");
}
}
public static boolean isLeapYear(int year){
if (year%4==0 && year%100!=0){
return true;
}
else{
if (year%400==0)
return true;
}
return false;
}
public static void Zellers(int year,int month,int day){
int LeapFactor,DayNumber,StartMonth,StartYear;
if (month<3)
{
StartMonth=0;
StartYear=year-1;
}
else
{
StartMonth = (int) (0.4*month+2.3);
StartYear = year;
}
LeapFactor =(StartYear/4)-(StartYear/100)+(StartYear/400);
DayNumber=((365*year+31*(month-1)+day+LeapFactor-StartMonth)-1)%7;
System.out.println("\n"+DisplayDay(DayNumber)+ " was Feb 29th in "+year);
for (int year1=year; year1>1582; year1++)
{
int DayNumber1=((365*year1+31*(month-1)+day+LeapFactor-StartMonth)-1)%7;
if(isLeapYear(year1) && DayNumber1==DayNumber)
{
System.out.println("\n"+year1+" is the next leap year where Feb. 29th happens on "+DisplayDay(DayNumber));
System.out.println("\n**********************************END************************************");
return;
}
}
}
public static String DisplayDay(int DayNumber){
switch (DayNumber)
{
case 0:
return "Sunday";
case 1:
return "Monday";
case 2:
return "Tuesday";
case 3:
return "Wednesday";
case 4:
return "Thursday";
case 5:
return "Friday";
case 6:
return "Saturday";
default:
return "";
}
}
}
• If the year is a leap year or not.
• If the given year is a leap year, your program should then display
1. which day of the week was Feb 29th, and
2. the next leap year where Feb. 29th happens on the same week day.
18961896 is leap yearSaturday was Feb 29th in 1896
61924 is the next leap year where Feb. 29th happens on Saturday**********************************END************************************
>Exit code: 0
>java -cp . LeapYear
Please enter a year greater than 1582.
19241924 is leap yearFriday was Feb 29th in 1924
51952 is the next leap year where Feb. 29th happens on Friday**********************************END************************************
>Exit code: 0