Advertisement
Go-Ice

Sophomore Java Homework-P3.27

Oct 7th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. /**
  2.  * Date:2014.10.08
  3.  * @author LinChuWen
  4.  * NCHU EE,course number:2335
  5.  * course name:Object Oriented Language
  6.  *
  7.  * Textbook:Big Java: Late Objects - Cay S. Horstmann
  8.  * Problem:P3.27
  9.  */
  10. import java.util.Scanner;
  11. public class HW2_P3_27 {
  12.  
  13.     public static void main(String[] args) {
  14.         int month;
  15.         Scanner input = new Scanner(System.in);
  16.  
  17.         try{
  18.             System.out.print("Please enter a month: ");
  19.             month = input.nextInt();
  20.             switch(month){
  21.                 case 1:
  22.                 case 3:
  23.                 case 5:
  24.                 case 7:
  25.                 case 8:
  26.                 case 10:
  27.                 case 12:
  28.                     System.out.println("31 days");
  29.                     break;
  30.                
  31.                 case 4:
  32.                 case 6:
  33.                 case 9:
  34.                 case 11:
  35.                     System.out.println("30 days");
  36.                     break;
  37.                    
  38.                 case 2:
  39.                     System.out.println("28 or 29 days");
  40.                     break;
  41.             } //switch end
  42.         } //try end
  43.        
  44.         catch(Exception ex){
  45.             System.out.println("Wrong Input!");
  46.         } //catch end
  47.        
  48.         finally{
  49.             input.close();
  50.         } //finally end
  51.     } //main end
  52. } //class end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement