-
Notifications
You must be signed in to change notification settings - Fork 0
/
644.java
78 lines (73 loc) · 2.9 KB
/
644.java
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.util.Scanner;
public class DaysInMonth {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int days = 0;
String monthName = "";
int year = 0;
boolean validInput = false;
while (!validInput) {
System.out.print("Enter the month (e.g., January, Jan, or 1): ");
String monthInput = scanner.next();
System.out.print("Enter the year: ");
year = scanner.nextInt();
if (monthInput.matches("^(January|Jan|1)$")) {
monthName = "January";
days = 31;
validInput = true;
} else if (monthInput.matches("^(February|Feb|2)$")) {
monthName = "February";
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {
days = 29; // Leap year
} else {
days = 28;
}
validInput = true;
} else if (monthInput.matches("^(March|Mar|3)$")) {
monthName = "March";
days = 31;
validInput = true;
} else if (monthInput.matches("^(April|Apr|4)$")) {
monthName = "April";
days = 30;
validInput = true;
} else if (monthInput.matches("^(May|5)$")) {
monthName = "May";
days = 31;
validInput = true;
} else if (monthInput.matches("^(June|Jun|6)$")) {
monthName = "June";
days = 30;
validInput = true;
} else if (monthInput.matches("^(July|Jul|7)$")) {
monthName = "July";
days = 31;
validInput = true;
} else if (monthInput.matches("^(August|Aug|8)$")) {
monthName = "August";
days = 31;
validInput = true;
} else if (monthInput.matches("^(September|Sep|Sept|9)$")) {
monthName = "September";
days = 30;
validInput = true;
} else if (monthInput.matches("^(October|Oct|10)$")) {
monthName = "October";
days = 31;
validInput = true;
} else if (monthInput.matches("^(November|Nov|11)$")) {
monthName = "November";
days = 30;
validInput = true;
} else if (monthInput.matches("^(December|Dec|12)$")) {
monthName = "December";
days = 31;
validInput = true;
} else {
System.out.println("Invalid month. Please try again.");
}
}
System.out.println("Month: " + monthName + ", Year: " + year + ", Days: " + days);
scanner.close();
}
}