Readability is the worst Please forgive that January will come in 2017.
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.YearMonth;
import java.util.Arrays;
import java.util.stream.IntStream;
public class PremiumFriday {
public static void main(String[] args) {
String year = "2017";
Arrays.stream(Month.values()).map(m ->IntStream.range(1,YearMonth.of(Integer.parseInt(year), m).atEndOfMonth().lengthOfMonth()+1).mapToObj(d -> LocalDate.of(Integer.parseInt(year), m, d)).filter(d -> DayOfWeek.FRIDAY.equals(d.getDayOfWeek())).max(LocalDate::compareTo)).forEach(o -> System.out.println(o.get()));
}
}
Former story I made a method to find Premium Friday I made a method to find Premium Friday (Java 8 version)
※※※ I made the year a String because I was thinking, "Would you like to take it from args? But it's annoying to pass it." Also, I feel that the input value in Java is somehow String. Int or java.time.Year is natural.
Recommended Posts