hpilo

Chapter2_SyntaxA_Ex10

Dec 15th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*  ==================================================
  4.      Chapter 2: Syntax section A- conditional clause
  5.  
  6.                   Ex10: Seasons
  7.     ===================================================
  8. */
  9.  
  10. public class MyProgram {
  11.     public static void main(String[] args) {
  12.  
  13.         //variables
  14.         double date;
  15.         int year,month,day;
  16.         Scanner s=new Scanner(System.in);
  17.  
  18.         //user input
  19.         System.out.println("\nEnter a date: ");
  20.         date=s.nextDouble();
  21.  
  22.         //separate number accordingly
  23.         year=(int)date%10000;
  24.         month=(int)(date/10000)%100;
  25.         day=(int)(date/1000000);
  26.  
  27.  
  28.         switch (month){
  29.  
  30.             case 3: case 4: case 5:
  31.                 System.out.println("Spring");
  32.                 break;
  33.             case 6: case 7: case 8:
  34.                 System.out.println("Summer");
  35.                 break;
  36.             case 9: case 10: case 11:
  37.                 System.out.println("Fall");
  38.                 break;
  39.             case 12: case 1: case 2:
  40.                 System.out.println("Winter");
  41.                 break;
  42.  
  43.             default:
  44.                 System.out.println("Invalid month");
  45.                 break;
  46.  
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment