Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /* ==================================================
- Chapter 2: Syntax section A- conditional clause
- Ex10: Seasons
- ===================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- //variables
- double date;
- int year,month,day;
- Scanner s=new Scanner(System.in);
- //user input
- System.out.println("\nEnter a date: ");
- date=s.nextDouble();
- //separate number accordingly
- year=(int)date%10000;
- month=(int)(date/10000)%100;
- day=(int)(date/1000000);
- switch (month){
- case 3: case 4: case 5:
- System.out.println("Spring");
- break;
- case 6: case 7: case 8:
- System.out.println("Summer");
- break;
- case 9: case 10: case 11:
- System.out.println("Fall");
- break;
- case 12: case 1: case 2:
- System.out.println("Winter");
- break;
- default:
- System.out.println("Invalid month");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment