-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDaysInEachMonth.java
45 lines (37 loc) · 1.03 KB
/
DaysInEachMonth.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
import java.util.Scanner;
public class DaysInEachMonth {
public static void main(String args[]){
Scanner keyboard = new Scanner(System.in);
int month, numberOfDays = 0;
boolean isLeapYear;
System.out.print("Which month? ");
month = keyboard.nextInt();
switch (month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
numberOfDays = 31;
break;
case 4:
case 6:
case 9:
case 11:
numberOfDays = 30;
break;
case 2:
System.out.print("Leap year (true/false)? ");
isLeapYear = keyboard.nextBoolean();
if(isLeapYear){
numberOfDays = 29;
}else {
numberOfDays = 28;
}
}
System.out.println(numberOfDays + " days");
keyboard.close();
}
}