-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindTheNumberOfDaysInMonth.java
More file actions
79 lines (76 loc) · 2.23 KB
/
findTheNumberOfDaysInMonth.java
File metadata and controls
79 lines (76 loc) · 2.23 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
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
79
/*
@author Muhammed Fatih ÖZDİL
@since 03/03/2021
*/
package algorithmExamples;
import java.util.Scanner;
public class findTheNumberOfDaysInMonth {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("enter a month number:");
int month = scanner.nextInt();
System.out.print("enter a year:");
int year = scanner.nextInt();
scanner.close();
int daysInmonth = 0;
String nameOfMonth = "";
switch (month) {
case 1:
nameOfMonth = "january";
daysInmonth = 31;
break;
case 2:
nameOfMonth = "February";
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
daysInmonth = 29;
}
daysInmonth = 28;
break;
case 3:
nameOfMonth = "March";
daysInmonth = 31;
break;
case 4:
nameOfMonth = "April";
daysInmonth = 30;
break;
case 5:
nameOfMonth = "May";
daysInmonth = 31;
break;
case 6:
nameOfMonth = "June";
daysInmonth = 30;
break;
case 7:
nameOfMonth = "July";
daysInmonth = 31;
break;
case 8:
nameOfMonth = "August";
daysInmonth = 31;
break;
case 9:
nameOfMonth = "September";
daysInmonth = 30;
break;
case 10:
nameOfMonth = "October";
daysInmonth = 31;
break;
case 11:
nameOfMonth = "November";
daysInmonth = 30;
break;
case 12:
nameOfMonth = "December";
daysInmonth = 31;
break;
default:
System.out.println("wrong month");
break;
}
System.out.println(nameOfMonth + " " + year + " has " + daysInmonth
+ " days");
}
}