forked from Rjndrkha/Data-Structure_Code-Program
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeason.java
More file actions
45 lines (36 loc) · 1.14 KB
/
Season.java
File metadata and controls
45 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.Scanner;
class Season {
private static boolean isSpring(int month) {
return month >= 3 && month <= 5;
}
private static boolean isSummer(int month) {
return month >= 6 && month <= 8;
}
private static boolean isAutumn(int month) {
return month >= 9 && month <= 11;
}
private static boolean isWinter(int month) {
return month == 1 || month == 2 || month == 12;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int month;
String season = "";
System.out.println("Enter the month:");
month = scanner.nextInt();
if (month < 1 || month > 12) {
System.out.println("Invalid month");
} else {
if (isSpring(month)) {
season = "Spring";
} else if (isAutumn(month)) {
season = "Autumn";
} else if (isSummer(month)) {
season = "Summer";
} else if (isWinter(month)) {
season = "Winter";
}
System.out.println("Season:" + season);
}
}
}