Program 2 – Seasons in the sun Create a Java application which will prompt the user to type in any month number (1-12). Implement a switch statement that will display the season. The seasons according to the months are: 1. Summer: November, December, January and February 2. Autumn: March, April and May. 3. Winter: June, July, August. 4. Spring: September and October
import java.util.Scanner;
public class Seasons {
	
	// This program is suitable from the southern hemisphere.
	// For example, Australia, where June is in winter etc.
	public static void main(String args[])
	{try (Scanner sc = new Scanner(System.in))
		{System.out.println("Please enter the number of the month or 's' to stop.");
		while(sc.hasNext())
		{switch (sc.next())
			{case "3":
			case "4":
			case "5":
				System.out.println("Autumn");
				break;
			case "6":
			case "7":
			case "8":
				System.out.println("Winter");
				break;
			case "9":
			case "10":
				System.out.println("Spring");
				break;
			case "11":
			case "12":
			case "1":
			case "2":
				System.out.println("Summer");
				break;
			case "s":
				return;
				default:
					System.out.println("The input is incorrect. \n"
							+ "Please enter number of the month between 1 and 12 or 's' to stop.");}}
		
		};}
}
Comments