Guest User

Untitled

a guest
Jan 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.     P3.12
  5. */
  6. public class SeasonsAlgorithm
  7. {
  8.     public static void main(String[] args)
  9.     {
  10.         Scanner in = new Scanner(System.in);
  11.  
  12.         // Season
  13.         String season;
  14.  
  15.         // Month
  16.  
  17.         System.out.print("Enter month: ");
  18.         if (!in.hasNextInt())
  19.         {
  20.             int month = in.nextInt();
  21.  
  22.             if (month == 1 || month == 2 || month == 3)
  23.             {
  24.             season = "Winter";
  25.             System.out.print("The season is ");
  26.             System.out.println(season);
  27.             }
  28.             else if (month == 4 || month == 5 || month == 6)
  29.             {
  30.             season = "Spring";
  31.             System.out.print("The season is ");
  32.             System.out.println(season);
  33.             }
  34.             else if (month == 7 || month == 8 || month == 9)
  35.             {
  36.             season = "Summer";
  37.             System.out.print("The season is ");
  38.             System.out.println(season);
  39.             }
  40.             else if (month == 10 || month == 11 || month == 12)
  41.             {
  42.             season = "Fall";
  43.             System.out.print("The season is ");
  44.             System.out.println(season);
  45.             }
  46.         }
  47.  
  48.         //Day
  49.  
  50.         System.out.print("Enter day: ");
  51.         if (!in.hasNextInt())
  52.         {
  53.             int day = in.nextInt();
  54.  
  55.             if (month % 3 == 0 && day >= 21)
  56.             {
  57.                 if (season.equals("Winter"))
  58.                 {
  59.                 season = "Spring";
  60.                 System.out.print("The season is ");
  61.                 System.out.println(season);
  62.                 }
  63.                 else if (season.equals("Spring"))
  64.                 {
  65.                 season = "Summer";
  66.                 System.out.print("The season is ");
  67.                 System.out.println(season);
  68.                 }
  69.                 else if (season.equals("Summer"))
  70.                 {
  71.                 season = "Fall";
  72.                 System.out.print("The season is ");
  73.                 System.out.println(season);
  74.                 }
  75.                 else
  76.                 {
  77.                 season = "Winter";
  78.                 System.out.print("The season is ");
  79.                 System.out.println(season);
  80.                 }
  81.             }
  82.         }
  83.  
  84.     }
  85. }
Add Comment
Please, Sign In to add comment