/** * SwitchEnumDemo.java is an application that compiles and runs * under J2SE 5.0 (and *not* under earlier releases). * It requires no other files. * * It's an enum-based equivalent to SwitchDemo2.java. */ public class SwitchEnumDemo { public enum Month { JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER } public static void main(String[] args) { Month month = Month.FEBRUARY; int year = 2000; int numDays = 0; switch (month) { case JANUARY: case MARCH: case MAY: case JULY: case AUGUST: case OCTOBER: case DECEMBER: numDays = 31; break; case APRIL: case JUNE: case SEPTEMBER: case NOVEMBER: numDays = 30; break; case FEBRUARY: if ( ((year % 4 == 0) && !(year % 100 == 0)) || (year % 400 == 0) ) numDays = 29; else numDays = 28; break; default: numDays = 0; break; } System.out.println("Number of Days = " + numDays); } }