In: Computer Science
Online banking is quick and c Among those people who have an online% approximation to a binomial distribution with continuity correction.
This program computes and prints the current season of the
year
depending on the month and day.
*/
import java.util.Scanner;
public class Seasons {
public static void main(String[] args) {
//default value for the variables month, day and season
int month = 0; // month is set to 0
int day = 0; // day is set to 0
String season = null; // season is set to null
// Creates scanner object
Scanner input = new Scanner(System.in);
System.out.print("Enter a month (ex: 12) : ");
// Check to see if the input is a integer for month value
if(input.hasNextInt()){
month = input.nextInt(); v
The code to finding the Season from the month is given below,
Seasons.java
import java.util.Scanner;
public class Seasons {
public static void main(String[] args) {
//default value for the variables month, day and season
int month = 0; // month is set to 0
int day = 0; // day is set to 0
String season = null; // season is set to null
// Creates scanner object
Scanner sc = new Scanner(System.in);
System.out.print("Enter a month (ex: 12) : ");
month = sc.nextInt();
System.out.print("Enter day (ex: 3) : ");
day = sc.nextInt();
outer:
while(true){
switch (month) {
case 12:
case 1:
case 2:
season = "Winter";
break outer;
case 3:
case 4:
case 5:
season = "Spring";
break outer;
case 6:
case 7:
case 8:
season = "Summmer";
break outer;
case 9:
case 10:
case 11:
season = "Autumn";
break outer;
default:
System.out.println("Invalid Month number entered. Month should be b/w 1-12.");
System.out.print("Enter a month (ex: 12) : ");
month = sc.nextInt();
}
}
System.out.println("Season : "+season);
}
}
If you have any doubt about this or wants any other method to be added then put in the comments section or update the question. Also, do upvote the solution.