Java Month loop through each month

Description

Java Month loop through each month

import java.time.Month;
import java.time.YearMonth;

public class Main {
  public static void main(String[] args) {
    int year = 2020;

    System.out.printf("For the year %d:%n", year);
    for (Month month : Month.values()) {
      YearMonth ym = YearMonth.of(year, month);
      System.out.printf("%s: %d days%n", month, ym.lengthOfMonth());
    }//from   w  w  w.jav  a  2s .c  o  m
  }
}



PreviousNext

Related