Skip to content
Advertisement

Calculate the date of Easter Sunday

Write a program to compute the date of Easter Sunday. Easter Sunday is the first Sunday after the first full moon of spring. Use the algorithm invented by the mathematician Carl Friedrich Gauss in 1800:

  1. Let y be the year (such as 1800 or 2001)
  2. Divide y by 19 and call the remainder a. Ignore the quotient.
  3. Divide y by 100 to get a quotient b and a remainder c.
  4. Divide b by 4 to get a quotient d and a remainder e.
  5. Divide 8 * b + 13 by 25 to get a quotient g. Ignore the remainder.
  6. Divide 19 * a + b - d - g + 15 by 30 to get a remainder h. Ignore the quotient.
  7. Divide c by 4 to get a quotient j and a remainder k.
  8. Divide a + 11 * h by 319 to get a quotient m. Ignore the remainder.
  9. Divide 2 * e + 2 * j - k - h + m + 32 by 7 to get a remainder r. Ignore the quotient.
  10. Divide h - m + r + 90 by 25 to get a quotient n. Ignore the remainder.
  11. Divide h - m + r + n + 19 by 32 to get a remainder of p. Ignore the quotient.

Then Easter falls on a day p of month n.

For example, if y is 2001:

JavaScript

Therefore, in 2001, Easter Sunday fell on April 15.

Make sure you prompt the user for a year and have the user input the year. Also, make sure you output the values of p and n with the appropriate messages describing the values output.


I’m having a little trouble putting this into Java code. Here’s what I’ve tried:

JavaScript

This is what I have. I don’t know how to assign stuff, like I tried to get getEasterSundayMonth to equal the value of n, pretty sure its not right. Where do I go from here?

Advertisement

Answer

Try this:

JavaScript

An input of 2001 results in April 15 as the output.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement