public static boolean isEaster(int month, int day, int year) isEaster : This met
ID: 3566305 • Letter: P
Question
public static boolean isEaster(int month, int day, int year) isEaster : This method has 3 int type parameters for month, day and year. This method returns true if the date represented by is Easter, otherwise it returns false. To implement this method: use the following formula to figure out the month and the day of Easter for the given year. goldenNumber = (year % 19) + 1; a = (24 + 19*(goldenNumber - 1)) % 30; b = a - a/28; c = (year + year/4 + b - 13) % 7; d = b - c; easterMonth = 3 + (d + 40)/44; easterDay = d + 28 - 31*(easterMonth/4);
Explanation / Answer
public static boolean isEaster(int month,int day,int year){
int goldenNumber = (year % 19) + 1;
int a = (24 + 19*(goldenNumber - 1)) % 30;
int b = a - a/28;
int c = (year + year/4 + b - 13) % 7;
int d = b - c;
int easterMonth,easterDay;
if((easterMonth = 3 + (d + 40)/44) == month){
if((easterDay = d + 28 - 31*(easterMonth/4)) == day){
return true;
}
}
return false;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.