Java Year check leap year

Description

Java Year check leap year

import java.time.Year;

public class Main {
  public static void main(String[] args) {
    Year y = Year.now(); //from  w  w w  .  j a  va 2 s . com
    System.out.println(y);
    
    if (y.isLeap()) {
      System.out.println(y + " is a leap year.");
    } else {
      System.out.println(y + " is not a leap year.");
    }
  }
}



PreviousNext

Related