A Problem Solved: Day of the Week
In this lesson, we will use the if statement to find what day of the week a given date falls.
We'll cover the following
Problem statement
On what day of the week does a given date fall? The date is given as three integers mm, dd, and yyyy, where
- mm is the number of the month and ranges from 1 to 12
- dd represents the day and ranges from 1 to 31
- yyyy is the four-digit year
The Day of the Week problem discussed in an earlier chapter presented a pseudocode solution to finding the day of the week on which a given date falls. At the time, we had not discussed the if
statement. Now that we have done so, we can write a complete Java program to solve this problem.
Solution
Our solution is given below. Compare the program to the incomplete solution that we just mentioned. Then execute the program by clicking the RUN button.
Get hands-on with 1400+ tech skills courses.