| Zeller's Congruence |
|
|
|
| Written by Charles | |||||||||||||||||||||||||||||||||||||||||
| Saturday, 20 September 2008 08:07 | |||||||||||||||||||||||||||||||||||||||||
|
This is a Java implementation of 'Zeller's Congruence', an algorithm for calculating the day of the week,
import java.util.*;
public class Zeller { /** * A demo implementation of 'Zeller's Congruence' for the Gregorian Calendar * See http://en.wikipedia.org/wiki/Zeller's_congruence * * @param args (Not used) */ final static String[] DAYS_OF_WEEK = { "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" }; public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the date in dd/mm/yyyy form: "); String[] atoms = input.nextLine().split("/"); int q = Integer.parseInt(atoms[0]); int m = Integer.parseInt(atoms[1]); int y = Integer.parseInt(atoms[2]); if (m < 3) { m += 12; y -= 1; } int k = y % 100; int j = y / 100; int day = ((q + (((m + 1) * 26) / 10) + k + (k / 4) + (j / 4)) + (5 * j)) % 7; System.out.println("That date was a " + DAYS_OF_WEEK[day] + "."); } }
Only registered users can write comments!
Powered by !JoomlaComment 3.26
3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved." |
|||||||||||||||||||||||||||||||||||||||||
| Last Updated ( Thursday, 11 June 2009 08:37 ) | |||||||||||||||||||||||||||||||||||||||||



