Social Icons

banner image

The Date of Easter Problem


A convenient algorithm for determining the date of Easter in a given year was devised
in 1876 and rst appeared in Butcher's Ecclesiastical Handbook. The algorithm is valid
for all years in the Gregorian calendar. Subject to minor adaptations, the algorithm is as
follows:
1. Let y be the year
2. Set a to y%19
3. Set b to y/100 and c to y%100
4. Set d to b/4 and e to b%4
5. Set f to (b+8)/25
6. Set g to (b-f+1)/3
7. Set h to (19*a+b-d-g+15)%30
8. Set i to c/4 and k to c%4
9. Set l to (32+2*e+2*i-h-k)%7
10. Set m to (a+11*h+22*l)/451
11. Set n to (h+l-7*m+114)/31 and p to (h+l-7*m+114)%31
12. Determine 10*(p+1)+n
Note that all identi ers represent integers.
The value of n gives the month (3 for March and 4 for April) and the value of p+1 gives
the day of the month. These two values can be combined as 10*(p+1)+n when 23 April
would be given as 234.
Write a method private static int easter(int y) which, when presented with a
year y, returns the date of Easter in the form shown at step 12.
Incorporate this method into a complete test program. Verify that the method gives the
correct date of Easter for the current year.

solution

import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Shobhit
 */
public class q12 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("Enter the year y");
     
        int y = scanner.nextInt();
        int a = y% 19;
        int b = y/100;
        int c= y%100;
        int d= b/4;
        int e=b%4;
        int f = (b+8)/25;
        int g=(b-f+1)/3;
        int h=(19*a+b-d-g+15)%30;
        int i=c/4;
        int k= c%4;
        int l=(32+2*e+2*i-h-k)%7;
        int m=(a+11*h+22*l)/451;
        int n=(h+l-7*m+114)/31;
        int p= (h+l-7*m+114)%31;
        int z=10*(p+1)+n;
        System.out.println(z);
     
        System.out.println(z+n);
         

       
       
    }
   
}

The Date of Easter Problem The Date of Easter Problem Reviewed by Shobhit Goel on January 27, 2016 Rating: 5

No comments:

Airtel Hackaton 2017

Powered by Blogger.