Answer to Question #200838 in Java | JSP | JSF for Aubrey Eso Jozela

Question #200838

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 


1
Expert's answer
2021-05-31T00:53:21-0400
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.");}}
		
		};}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS