import java.util.Calendar; import java.util.GregorianCalendar; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { int yearTotalHappyDay = IntStream.rangeClosed(1, 12) .mapToObj(Month::of) .mapToInt(Month::getTotalHappyDay) .sum(); System.out.println(yearTotalHappyDay); } private static class Month { private int month; private int maxDay; private Month(int month, int maxDay) { this.month = month; this.maxDay = maxDay; } public static Month of(int month) { int maxDay = new GregorianCalendar(2015, (month - 1), 1).getActualMaximum(Calendar.DAY_OF_MONTH); return new Month(month, maxDay); } public int getTotalHappyDay() { return IntStream.rangeClosed(1, maxDay) .mapToObj(day -> isHappyDay(month, day)) .mapToInt(happyDay -> (happyDay) ? 1 : 0) .sum(); } private Boolean isHappyDay(int month, int day) { String twoDigitsDay = String.format("%02d", day); String tensPlace = twoDigitsDay.substring(0, 1); int tensPlaceNum = tensPlace.isEmpty() ? 0 : Integer.parseInt(tensPlace); int onesPlaceNum = Integer.parseInt(twoDigitsDay.substring(1, 2)); return (month == (tensPlaceNum + onesPlaceNum)); } } }