- 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
LocalDate isLeapYear() method in Java
It can be checked if the LocalDate is in a leap year or not using the isLeapYear() method in the LocalDate class in Java. This method requires no parameters. It returns true if the LocalDate is in a leap year and false otherwise.
A program that demonstrates this is given as follows −
Example
import java.time.*; public class Main { public static void main(String[] args) { LocalDate ld = LocalDate.parse("2012-10-12"); System.out.println("The LocalDate is: " + ld); boolean flag = ld.isLeapYear(); if(flag) System.out.println("This is a leap year"); else System.out.println("This is not a leap year"); } }
Output
The LocalDate is: 2012-10-12 This is a leap year
Now let us understand the above program.
The LocalDate object is displayed. It is checked if the LocalDate object is in a leap year or not using the isLeapYear() method. The returned value is displayed using an if statement. A code snippet that demonstrates this is as follows −
LocalDate ld = LocalDate.parse("2012-10-12"); System.out.println("The LocalDate is: " + ld); boolean flag = ld.isLeapYear(); if(flag) System.out.println("This is a leap year"); else System.out.println("This is not a leap year");
Advertisements