Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- P3.12
- */
- public class SeasonsAlgorithm
- {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- // Season
- String season;
- // Month
- System.out.print("Enter month: ");
- if (!in.hasNextInt())
- {
- int month = in.nextInt();
- if (month == 1 || month == 2 || month == 3)
- {
- season = "Winter";
- System.out.print("The season is ");
- System.out.println(season);
- }
- else if (month == 4 || month == 5 || month == 6)
- {
- season = "Spring";
- System.out.print("The season is ");
- System.out.println(season);
- }
- else if (month == 7 || month == 8 || month == 9)
- {
- season = "Summer";
- System.out.print("The season is ");
- System.out.println(season);
- }
- else if (month == 10 || month == 11 || month == 12)
- {
- season = "Fall";
- System.out.print("The season is ");
- System.out.println(season);
- }
- }
- //Day
- System.out.print("Enter day: ");
- if (!in.hasNextInt())
- {
- int day = in.nextInt();
- if (month % 3 == 0 && day >= 21)
- {
- if (season.equals("Winter"))
- {
- season = "Spring";
- System.out.print("The season is ");
- System.out.println(season);
- }
- else if (season.equals("Spring"))
- {
- season = "Summer";
- System.out.print("The season is ");
- System.out.println(season);
- }
- else if (season.equals("Summer"))
- {
- season = "Fall";
- System.out.print("The season is ");
- System.out.println(season);
- }
- else
- {
- season = "Winter";
- System.out.print("The season is ");
- System.out.println(season);
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment