Created
February 17, 2025 11:45
-
-
Save sunghyuck-cpf21b/33740da68613c32d700c4199751126d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 양성혁 | |
| import java.time.LocalDate; | |
| import java.util.Scanner; | |
| public class Main { | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| System.out.print("달력의 년도를 입력해 주세요.(yyyy): "); | |
| int year = sc.nextInt(); | |
| System.out.print("달력의 월을 입력해 주세요.(mm): "); | |
| int month = sc.nextInt(); | |
| for (int i = -1; i <= 1; i++) { | |
| LocalDate monthData = LocalDate.of(year, month, 1).plusMonths(i); | |
| int _year = monthData.getYear(); | |
| int _month = monthData.getMonthValue(); | |
| System.out.println("[" + _year + "년 " + _month + "월]"); | |
| System.out.println("일\t월\t화\t수\t목\t금\t토"); | |
| // 월~일 -> 일~토 변환 | |
| int day = monthData.getDayOfWeek().getValue(); | |
| day = day == 7 ? 0 : day; | |
| int monthLength = monthData.lengthOfMonth(); | |
| int weeks = (day + monthLength)/7 + 1; | |
| for (int j = 0; j < (weeks); j++) { | |
| for (int k = 0; k < 7; k++) { | |
| int base = j * 7 + k + 1; | |
| // 해당 달의 날짜만 출력 | |
| if (day < base && base < day + monthLength + 1) { | |
| System.out.printf("%02d\t", base - day); | |
| } else { | |
| System.out.print("\t"); | |
| } | |
| } | |
| System.out.println(); | |
| } | |
| System.out.println(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment