How to find number of days and weeks for given month in Java?



Problem Description :


Write a program in Java that displays number of days and weeks for given month with proper validations.

Concept :


We know that number of days are constant for each month except February because for leap year there are 29 days and for other years 28 days. So in this problem if any user enter month name as February then he has to enter year also for finding number of days. The Solution is very simple and straight forward. We are using switch case for finding number of day and division/remainder mechanism for number of weeks.


Recommended :



Java Program :




Output :


Case 1 :


Output of Java program that finds number of days and weeks for given month - case1
Output - Other than Feb month 

Case 2 :


Output of Java program that finds number of days and weeks for given month - case2
Output - Feb month

References :


https://en.wikipedia.org/wiki/Regular_expression

https://docs.oracle.com/javase/7/docs/api/java/lang/String.html

https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html

https://docs.oracle.com/javase/7/docs/api/java/util/List.html

https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html

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, Days and weeks for given month, Solution in Java, String, if else statement, List, ArrayList, Regular expressions, switch statement, Leap year.

About Author:

I am simple guy with lot of ambitions. My main motive is to share whatever knowledge I have related to programming. With me you can easily learn how to solve any programming problem in Java.You can connect with me on social networking sites also.


Let's Get Connected: Linkedin | Facebook |

How to find number of days and weeks for given month in Java? How to find number of days and weeks for given month in Java? Reviewed by Rohit Agarwal on 1/20/2017 Rating: 5

No comments:

Please provide your valuable comments. If you have any suggestion please share with me I will work on it and if you have any question or doubt please ask, don't hesitate. I am your friend, i will clarify all your doubts.

Powered by Blogger.