# Thread: Need help with Zeller's Congruence

1. Member
Join Date
Feb 2013
Posts
2
Rep Power
0

## 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

Java 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);

}```
Last edited by quem; 02-24-2013 at 10:16 AM.

2. ## Re: Need help with Zeller's Congruence

Your step #8 is incorrect; see this: Zeller's congruence - Wikipedia, the free encyclopedia

kind regards,

Jos

3. Member
Join Date
Feb 2013
Posts
2
Rep Power
0

## Re: Need help with Zeller's Congruence

Originally Posted by JosAH
Your step #8 is incorrect; see this: Zeller's congruence - Wikipedia, the free encyclopedia

kind regards,

Jos
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!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•