-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava149_Calendar.java
More file actions
57 lines (46 loc) · 946 Bytes
/
Copy pathJava149_Calendar.java
File metadata and controls
57 lines (46 loc) · 946 Bytes
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
package java0907_api;
import java.text.SimpleDateFormat;
import java.util.Calendar;
/*
* 2016년 2월 마지막일과 요일을 구하는 프로글매을 구현하세요.
* [출력결과]
* 2016-2-29 월요일
*/
public class Java149_Calendar {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
int year = 2016;
int month = 2;
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month - 1);
// 마지막일
int date = cal.getActualMaximum(Calendar.DATE);
// 요일
int day = cal.get(Calendar.DAY_OF_WEEK);
String week = "";
switch (day) {
case 1:
week = "일";
break;
case 2:
week = "월";
break;
case 3:
week = "화";
break;
case 4:
week = "수";
break;
case 5:
week = "목";
break;
case 6:
week = "금";
break;
case 7:
week = "토";
break;
}
System.out.printf("%d-%d-%d %s요일\n", year, month, date, week);
}
}