## Problem Description :

Write a program in Java that prints all the Mondays in given month and year. For example in Jan
2017 there are 5 Mondays and dates are 02/01/2017, 09/01/2017, 16/01/2017, 23/01/2017, 30/01/2017.

## Concept :

If you have read our previous date and time problems then believe me this problem would be piece of cake for you. With the help of Calendar class constants MONTH, YEARDAY_OF_MONTH and DAY_OF_WEEK we can easily solve this problem.

## Algorithm :

1. Find number of days in given month.
2. Set given month and year in Calendar.
3. Iterate the loop from 1 to number of days ( Step 1 ) times.
4. Set the day of month as current index in Calendar.
5. Check the day, if it is Monday print it else go to Step 3.

## Output :

 Output - Monday's in given month and year in Java

## Similar Problems :

1) How to print all the Sundays in given month and year?

- Replace line 76 with if (cal.get(Calendar.DAY_OF_WEEK) == 1) {

2) How to print all the Tuesdays in given month and year?

- Replace line 76 with if (cal.get(Calendar.DAY_OF_WEEK) == 3) {

3) How to print all the Wednesdays in given month and year?

- Replace line 76 with if (cal.get(Calendar.DAY_OF_WEEK) == 4) {

4) How to print all the Thursdays in given month and year?

- Replace line 76 with if (cal.get(Calendar.DAY_OF_WEEK) == 5) {

5) How to print all the Fridays in given month and year?

- Replace line 76 with if (cal.get(Calendar.DAY_OF_WEEK) == 6) {

6) How to print all the Saturdays in given month and year?

- Replace line 76 with if (cal.get(Calendar.DAY_OF_WEEK) == 7) {

## References :

Thank you friends, I hope you have clearly understood the solution of this problem. If you have any doubt, suggestion or query please feel free to comment below. You can also discuss this solution in our forum.

Tags : Date and Time Problems, DateFormat, SimpleDateFormat, String, Calendar, if else statement, switch statement, List, ArrayList, Leap Year.