Java Date Time Java Java API
Class:
java.time.Year
Methods:
public boolean isLeap()
Checks if this year object is a leap year.
public static boolean isLeap(long year)
Checks if the provided year is a leap year.
Examples
package com.logicbig.example.year;
import java.time.Year;
public class IsLeapExample {
public static void main(String... args) { Year y = Year.of(2011); System.out.println(y);
boolean b = y.isLeap(); System.out.println(b);
Year y2 = Year.of(2020); System.out.println(y2); boolean b2 = y2.isLeap(); System.out.println(b2); } }
Output2011 false 2020 true
package com.logicbig.example.year;
import java.time.Year;
public class IsLeapExample2 {
public static void main(String... args) { boolean b = Year.isLeap(2011); System.out.println(b);
boolean b2 = Year.isLeap(2020); System.out.println(b2); } }
Outputfalse true
|