Results 1 to 3 of 3
  1. #1
    quem is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default 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 09:16 AM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,453
    Blog Entries
    7
    Rep Power
    20

    Default Re: Need help with Zeller's Congruence

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

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    quem is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default Re: Need help with Zeller's Congruence

    Quote Originally Posted by JosAH View Post
    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
  •