package kr.or.ddit.homework;
import java.util.Calendar;
import java.util.Scanner;
public class HomeWork17 {
Scanner sc = new Scanner(System.in);
Calendar cal = Calendar.getInstance();
public static void main(String[] args) {
HomeWork17 hw = new HomeWork17();
hw.process();
}
public void process() {
while (true) {
// < 이전달, > 다음달 출력하기
int last = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH)+1;
System.out.println("----------------------" + cal.get(Calendar.YEAR) + "년 " + month
+ "월----------------------");
System.out.println("<이전달\t\t\t\t\t\t다음달>");
System.out.println("일\t월\t화\t수\t목\t금\t토");
System.out.println("-----------------------------------------------------");
cal.set(Calendar.DATE, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
int week = cal.get(Calendar.DAY_OF_WEEK);
for(int i=1; i<week;i++) {
System.out.print("\t");
}
for (int i = 1; i <= last; i++) {
System.out.print(i+"\t");
week = cal.get(Calendar.DAY_OF_WEEK);
if (week == 7) {
System.out.println();
}
cal.add(Calendar.DAY_OF_WEEK,1);
}
System.out.println();
// 다음달로 넘어감으로 1일 빼기
cal.add(Calendar.DAY_OF_WEEK,-1);
System.out.println("-----------------------------------------------------");
String sel = sc.next();
if(sel.equals("<")) {
cal.add(Calendar.MONTH, -1);
} else if(sel.equals(">")) {
cal.add(Calendar.MONTH, 1);
}
}
}
}
'JAVA > JAVA BASIC' 카테고리의 다른 글
3/28 Homework (0) | 2024.03.28 |
---|---|
[JAVA] Collection Framework (1) | 2024.03.28 |
[JAVA] 중첩 클래스, Unit 클래스 (0) | 2024.03.27 |
[JAVA] 상속 - 추상 클래스, 인터페이스 (0) | 2024.03.27 |
[JAVA] Getter Setter, 상속 (1) | 2024.03.26 |