import java.util.Calendar; /** * No.188 HAPPY DAY */ public class HappyDay { public static void main(String[] args) { int year = 2015; int lastDate = 0; int resNum = 0; int tensPlace = 0; int onePlace = 0; Calendar cal = Calendar.getInstance(); for (int month=1; month<=12; month++) { cal.clear(); cal.set(year, month - 1, 1); // 月末の日付を求める cal.add(Calendar.MONTH, 1); cal.add(Calendar.DATE, -1); lastDate = cal.get(Calendar.DATE); for (int date = 1; date <= lastDate; date++) { tensPlace = (int) Math.floor(date / 10); onePlace = date % 10; if (month == tensPlace+onePlace) resNum++; } } System.out.println(resNum); } }