-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise03_11.java
More file actions
67 lines (63 loc) · 1.87 KB
/
Copy pathExercise03_11.java
File metadata and controls
67 lines (63 loc) · 1.87 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
package Chapter3;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author jorda
*/
public class Exercise03_11 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Enter a month in the year (ex: 1 for Jan): ");
int month = input.nextInt();
System.out.println("Enter a year: ");
int year = input.nextInt();
String sMonth = "";
int daysInMonth = 0;
switch(month){
case 1: sMonth = "January";
daysInMonth = 31;
break;
case 2: sMonth = "February";
daysInMonth = 28;
break;
case 3: sMonth = "March";
daysInMonth = 31;
break;
case 4: sMonth = "April";
daysInMonth = 30;
break;
case 5: sMonth = "May";
daysInMonth = 31;
break;
case 6: sMonth = "June";
daysInMonth = 30;
break;
case 7: sMonth = "July";
daysInMonth = 31;
break;
case 8: sMonth = "August";
daysInMonth = 31;
break;
case 9: sMonth = "September";
daysInMonth = 30;
break;
case 10: sMonth = "October";
daysInMonth = 31;
break;
case 11: sMonth = "November";
daysInMonth = 30;
break;
case 12: sMonth = "December";
daysInMonth = 31;
break;
}
if (month == 2 && year%4 == 0) //leap year
daysInMonth = 29;
System.out.println(sMonth + " " + year + " has " + daysInMonth + " days.");
}
}