A Problem Partially Solved: Day of the Week
Explore how to calculate the day of the week from any date using Zeller's congruence algorithm. Learn to apply integer division, modulo operations, and conditional adjustments in Java to solve this common programming problem. This lesson strengthens your understanding of arithmetic expressions and prepares you for integrating decision-making in your Java programs.
We'll cover the following...
Problem statement
Various devices in our homes record the current date as the month, day, and year. When a date is displayed, it often includes the day of the week. Is it possible to ascertain the day of the week from the month, day, and year? The answer is yes, as you will soon see.
Discussion
An algorithm known as Zeller’s congruence makes the determination that we need. According to this algorithm, a date such as December 31, 2020, is described as three components, as follows:
- m is the month number, but one that is slightly different from what we are used to. March