Last active
January 5, 2023 14:07
-
-
Save FeelingXD/7fe98bd81c8bffabf87c396a743df846 to your computer and use it in GitHub Desktop.
달력
This file contains 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.util.Calendar; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
System.out.println("[달력 출력 프로그램]"); | |
Scanner input = new Scanner(System.in); | |
int year = int_check("달력의 년도를 입력해 주세요.(yyyy):",input,0,4000); | |
int month = int_check("달력의 월을 입력해 주세요.(mm):",input,1,12); | |
output_calendar(year,month); | |
} | |
public static int int_check(String message, Scanner input, int min, int max){ | |
try { | |
System.out.print(message); | |
int value= input.nextInt(); | |
if(value <min ||value>max){ | |
throw new Exception("범위 초과"); | |
} | |
return value; | |
}catch (Exception e){ | |
System.out.println(e.getMessage()); | |
System.out.println("다시 입력해주세요."); | |
return int_check(message,input,min,max); | |
} | |
} | |
public static void output_calendar(int year, int month){ | |
System.out.printf(" [%04d년 %02d월]\n",year,month); | |
System.out.println(" 일 월 화 수 목 금 토"); | |
Calendar calendar=Calendar.getInstance(); | |
calendar.set(year,month-1,1); | |
int week=calendar.get(Calendar.DAY_OF_WEEK); | |
for (int i=1;i<week;i++){ | |
System.out.print(" "); | |
} | |
for(int i=1;i<=calendar.getActualMaximum(Calendar.DATE);i++){ | |
System.out.printf(" %02d",i); | |
week++; | |
if(week%7==1){ | |
System.out.println(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment