The goal of this coding exam is to quickly get you off the ground with switch statement. given month as input,write a js program to find the corresponding season using switch statement
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String month = scanner.nextLine();
System.out.println(findSeasonOf(month));
}
private static String findSeasonOf(String month) {
switch (month.toLowerCase()) {
case "december":
case "january":
case "february":
return "Winter";
case "march":
case "april":
case "may":
return "Spring";
case "june":
case "july":
case "august":
return "Summer";
case "september":
case "october":
case "november":
return "Autumn";
default:
return "Unknown";
}
}
}
Comments
Leave a comment