년 월을 입력하면 달력이 그대로 출력
import java.io.*; public class pro_005a { public static void main(String[] ar) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int b = 0, c = 0, num1 = 0, num2 = 0; String str = " "; System.out.printf("1. 년도를 4자리로 입력하세요<예 : 2010> : "); str = in.readLine(); int year = Integer.parseInt(str); System.out.printf("2. 월을 입력하세요 <예 : 6> : "); str = in.readLine(); int month = Integer.parseInt(str); int day = 1, sum = 0, week = 0; int j = 0, i = 0; int neryo = 0, jinzza = 0; for (i = 1; i < year; i++) { sum += 365; if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) sum += 1; } for (i = 1; i < month; i++) { j = i; if (j == 1 || j == 3 || j == 5 || j == 7 || j == 8 || j == 10 || j == 12) j = 31; else if (j == 2) { j = 28; if (year % 4 == 0 && year % 10 != 0 || year % 400 == 0) j += 1; } else j = 30; sum += j; } sum += day; week = sum % 7; /* * week 이 다음 숫자이면... 해당 月의 1일은 * 0 1 2 3 4 5 6 * 일 월 화 수 목 금 토 */ if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) jinzza = 31; else if (month == 2) { jinzza = 28; if (year % 4 == 0 && year % 10 != 0 || year % 400 == 0) jinzza += 1; } else jinzza = 30; System.out.println("=================< " + year + "년 " + month + "월 >===================="); System.out.println("일 월 화 수 목 금 토 "); for (int e = 0; e < week; e++) { System.out.printf(" "); neryo++; } for (int q = 1; q <= jinzza; q++) { System.out.printf("%2d ", q); neryo++; if (neryo == 7) { System.out.printf(" "); neryo = 0; } } } }
'STUDY > Java' 카테고리의 다른 글
[JAVA] 자바 한줄 게시판 (0) | 2010.09.05 |
---|---|
[JAVA] 달력 출력 (0) | 2010.01.14 |
[java] 자바 환경 변수 등록 (0) | 2010.01.06 |