Switch-Case+(Java)

code public class SwitchDemo { public static void main(String[] args) {

int month = 8; String monthString; switch (month) { case 1: monthString = "January";       break; case 2: monthString = "February";      break; case 3: monthString = "March";         break; case 4: monthString = "April";         break; case 5: monthString = "May";           break; case 6: monthString = "June";          break; case 7: monthString = "July";          break; case 8: monthString = "August";        break; case 9: monthString = "September";     break; case 10: monthString = "October";      break; case 11: monthString = "November";     break; case 12: monthString = "December";     break; default: monthString = "Invalid month"; break; }       System.out.println(monthString); } }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public static void main(String args[]) { java.util.ArrayList futureMonths = new java.util.ArrayList;

int month = 8;

switch (month) { case 1: futureMonths.add("January"); case 2: futureMonths.add("February"); case 3: futureMonths.add("March"); case 4: futureMonths.add("April"); case 5: futureMonths.add("May"); case 6: futureMonths.add("June"); case 7: futureMonths.add("July"); case 8: futureMonths.add("August"); case 9: futureMonths.add("September"); case 10: futureMonths.add("October"); case 11: futureMonths.add("November"); case 12: futureMonths.add("December"); break; default: break; }

if (futureMonths.isEmpty) { System.out.println("Invalid month number"); } else { for (String monthName : futureMonths) { System.out.println(monthName); }   }  } } code August September October November December

//

class SwitchDemo2 { public static void main(String[] args) {

int month = 2; int year = 2000; int numDays = 0;

switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: numDays = 31; break; case 4: case 6: case 9: case 11: numDays = 30; break; case 2: if ( ((year % 4 == 0) && !(year % 100 == 0)) numDays = 29; else numDays = 28; break; default: System.out.println("Invalid month."); break; } System.out.println("Number of Days = " + numDays); } }
 * (year % 400 == 0) )

Number of Days = 29 code