intdaysInMonth=0; switch (month) { case Calendar.JANUARY: case Calendar.MARCH: case Calendar.MAY: case Calendar.JULY: case Calendar.AUGUST: case Calendar.OCTOBER: case Calendar.DECEMBER: daysInMonth = 31; break; case Calendar.APRIL: case Calendar.JUNE: case Calendar.SEPTEMBER: case Calendar.NOVEMBER: // daysInMonth = 30; break; // WRONG, INITIAL daysInMonth value IS USED!!! case Calendar.FEBRUARY: if (((year % 4 == 0) && !(year % 100 == 0)) || (year % 400 == 0)) { daysInMonth = 29; } else { daysInMonth = 28; } break; default: thrownewRuntimeException("Calendar in JDK does not work"); }
System.out.printf("There are %d days in this month.%n", daysInMonth); } }
intdaysInMonth= switch (month) { case Calendar.JANUARY: case Calendar.MARCH: case Calendar.MAY: case Calendar.JULY: case Calendar.AUGUST: case Calendar.OCTOBER: case Calendar.DECEMBER: yield31; case Calendar.APRIL: case Calendar.JUNE: case Calendar.SEPTEMBER: case Calendar.NOVEMBER: yield30; case Calendar.FEBRUARY: if (((year % 4 == 0) && !(year % 100 == 0)) || (year % 400 == 0)) { yield29; } else { yield28; } default: thrownewRuntimeException("Calendar in JDK does not work"); };
System.out.println("There are " + daysInMonth + " days in this month."); } }