- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MonthDay isValidYear() Method in Java
It can be checked if a year is valid or not for a MonthDay object using the isValidYear() method in the MonthDay class in Java. This method requires a single parameter i.e. the year which is to be checked. Also, it returns true if the year is valid for a MonthDay object and false if the year is not valid for a MonthDay object.
A program that demonstrates this is given as follows
Example
import java.time.*; public class Demo { public static void main(String[] args) { MonthDay md = MonthDay.parse("--02-21"); System.out.println("The MonthDay is: " + md); System.out.println("Year 2019 is valid for the MonthDay? " + md.isValidYear(2019)); } }
Output
The MonthDay is: --02-21 Year 2019 is valid for the MonthDay? true
Now let us understand the above program.
First the current MonthDay object is displayed. Then it is checked if a year is valid or not for the MonthDay object using the isValidYear() method. The returned value is printed. A code snippet that demonstrates this is as follows:
MonthDay md = MonthDay.parse("--02-21"); System.out.println("The MonthDay is: " + md); System.out.println("Year 2019 is valid for the MonthDay? " + md.isValidYear(2019));
Advertisements
To Continue Learning Please Login
Login with Google