package calendar;
import java.util.Calendar;
import java.util.Scanner;
public class Program {
public static void main(String[] args)
{
int []days = new int [42];
Scanner scan = new Scanner(System.in);
Calendar cal = Calendar.getInstance();
while(true)
{
//현재 연,월,일
int curYear = cal.get(Calendar.YEAR);
int curMonth = cal.get(Calendar.MONTH)+1; //0부터시작
int curDay = cal.get(Calendar.DATE);
cal.set(curYear,curMonth-1,1); //몇월의 1일에 해당하는 요일 구하기
int week = cal.get(Calendar.DAY_OF_WEEK);
int start = 2-week;
int end = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
for(int i=0,n=start; i<42; i++,n++)
if(1<=n && n<=end)
days[i]= n;
else
days[i]=0;
System.out.printf("<%d년 %d월 달력입니다>\n\n",curYear, curMonth);
System.out.printf("***%d일이 마지막 날 입니다***\n\n", end);
for(int i=0, n=1; i<42; i++, n++)
{
System.out.printf("%2d\t",days[i]);
if(n%7==0)
System.out.printf("\n");
}
System.out.printf("년도와 월을 입력하세요 : \n");
curYear=scan.nextInt();
curMonth=scan.nextInt();
}
}
}