Results 1 to 3 of 3
- 02-24-2013, 08:58 AM #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 09:16 AM.
- 02-24-2013, 12:07 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: Need help with Zeller's Congruence
Your step #8 is incorrect; see this: Zeller's congruence - Wikipedia, the free encyclopedia
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-25-2013, 05:04 AM #3
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks