The length() method is a built-in method of the Month ENUM which is used to get the number of days in this month instance. The number of days in a month can be 28, 30 or 31. Number of days in February in a leap year is 29.
This method accepts a boolean flag variable which indicates whether this Year is a leap year or not.
public int length(boolean leapYear)
Parameters: This method accepts a single parameter leapYear, which indicates whether this year is a leapYear or not.
Return Value: This method returns the length of this month in number of days present in it.
Below programs illustrate the above method:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.