일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- https://aws.amazon.com/ko/docker/
- https://sewonzzang.tistory.com/22
- https://jcon.tistory.com/189
- https://joshua1988.github.io/web-development/javascript/promise-for-beginners/
- https://goodgid.github.io/HTTP-Communicate-Process/
- https://appmaster.io/ko/blog/rest-apiran-mueosimyeo-dareun-yuhyeonggwa-eoddeohge-dareungayo
- https://siyoon210.tistory.com/130
- https://subicura.com/2017/01/19/docker-guide-for-beginners-1.html
- https://joshua1988.github.io/web-development/javascript/js-async-await/
- https://hi-zini.tistory.com/entry/%EB%B9%84%EB%8F%99%EA%B8%B0%EC%A0%81-%EB%B0%A9%EC%8B%9D-%EC%B2%98%EB%A6%AC-%EB%B0%A9%EB%B2%95-Callback-Promise-async-await
- Today
- Total
“Connecting the dots”
JAVA Study 달력 알고리즘 문제 본문
package mymain;
import java.util.Scanner;
import myutil.calender;
public class MyMain_달력 {
public static void main(String[] args) {
Scanner scanner =new Scanner(System.in);
//년도와 월을 입력받음
System.out.print("년도를 입력하세요(YYYY): ");
int year = scanner.nextInt();
System.out.print("월을 입력하세요(MM): ");
int month = scanner.nextInt();
//해당 월의 1일에 해당되는 요일
int dayOfWeek = calender.display_DayOfWeek(year, month,1);
calender.display_DayOfWeek(year, month, dayOfWeek);
//해당 월의 마지막 날짜
int lastDay = calender.display_LastDayOfMonth(year, month);
calender.display_LastDayOfMonth(year, month);
//달력 출력
calender.display_printCalendar(year, month, dayOfWeek, lastDay);
;
scanner.close();
}
}
package myutil;
public class calender {
//특정 년, 월, 일에 해당하는 요일
public static int display_DayOfWeek(int year, int month, int day) {
int[] t = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
if (month < 3) {
year -= 1;
}
int dayOfWeek = (year + year/4 - year/100 + year/400 + t[month-1] + day) % 7;
return dayOfWeek;
}
//특정 년, 월의 마지막 날짜
public static int display_LastDayOfMonth(int year, int month) {
int[] daysInMonth = {31,28,31,30,31,30,31,31,30,31,30,31};
if (month == 2 && isLeapYear(year)) {
return 29;
}
return daysInMonth[month-1];
}
//윤년인지 판별
public static boolean isLeapYear(int year) {
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
return true;
} else {
return false;
}
} else {
return true;
}
} else {
return false;
}
}
//달력 출력
public static void display_printCalendar(int year, int month, int dayOfWeek, int lastDay) {
System.out.println(year + "년 " + month + "월");
System.out.println("일 월 화 수 목 금 토");
for (int i = 0; i < dayOfWeek; i++) {
System.out.print(" ");
}
for (int i = 1; i <= lastDay; i++) {
System.out.printf("%2d ", i);
if ((i + dayOfWeek) % 7 == 0) {
System.out.println();
}
}
}
}
'JAVA' 카테고리의 다른 글
추상클래스 VS 인터페이스 (0) | 2023.04.24 |
---|---|
JAVA STUDY 상속 추상화 인터페이스 (0) | 2023.04.20 |
Java Study 배열 180도 돌리기 / 배열좌우바꾸기 (0) | 2023.04.12 |
JAVA 2차원배열 (0) | 2023.04.12 |
JAVAStuDY Stack Heap (0) | 2023.04.11 |