Need help with Zeller's Congruence
I am getting a correct result for recent dates but when I go back a couple of years it's incorrect.
I feel so stupid, I am a major noob at math & coding and this is for a lab so I could really use some help.
Thanks
Code:
import java.util.Scanner;
public class Lab02 {
/**
* @param args
*/
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
{
//step1
System.out.println("Enter a month, January = 1, February = 2, ... December = 12:");
int month = keyboard.nextInt();
//step2
System.out.println("Enter a day, 1-31:");
int day = keyboard.nextInt();
//step3
System.out.println("Enter a year:");
int year = keyboard.nextInt();
//step4
if (month <= 2)
{ month = month + 10;
year = year - 1;
}
else
month = month - 2;
//step5
int monthCor = (month * 26 - 2) / 10;
//step6
int century = year / 100;
//step7
int centuryRem = year % 100;
//step8
int yearCor = (century * 5) + centuryRem;
yearCor = (century / 4) + (centuryRem / 4);
//step9
int weekday = (day + monthCor + yearCor) % 7;
System.out.println(weekday);
}
Re: Need help with Zeller's Congruence
Your step #8 is incorrect; see this: Zeller's congruence - Wikipedia, the free encyclopedia
kind regards,
Jos
Re: Need help with Zeller's Congruence
Quote:
Originally Posted by
JosAH
I see now, yearCor was being written over by the second equation.
This worked:
int yearCor = (century * 5 + century / 4 + centuryRem / 4) + centuryRem;
Thanks Again!