/* MultiwayBranch5.java CIS 160 David G. Klick 2007-09-25 Demonstrates switch statement with fall-through (purposefully missing 'break' statements). This version takes leap years into account. No checking is done to see if the year is valid, so the user could enter a value like -50. */ import java.util.Scanner; public class MultiwayBranch5 { public static void main(String[] args) { int days = 0; Scanner kbd = new Scanner(System.in); System.out.print("What month number is it? "); int month = kbd.nextInt(); System.out.print("What year is it? "); int year = kbd.nextInt(); System.out.print(month + "/" + year + " has "); switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days = 31; break; case 4: case 6: case 9: case 11: days = 30; break; case 2: if ( ((year % 4 == 0) && !(year % 100 == 0)) || (year % 400 == 0)) { days = 29; } else { days = 28; } break; default: System.out.println("*Invalid month specified*"); } if (days > 0) { System.out.println(days + " days"); } } }