Calendar #1
import java.util.Scanner;
public class Calendar {
public static void main(String args[]) {
int year;
int month;
int totalDays = 0;
Scanner sc = new Scanner(System.in);
System.out.println("연도 입력 : ");
year = sc.nextInt();
System.out.println("월 입력 : ");
month = sc.nextInt();
switch(month)
{
case 1: case 3: case 5: case 7: case 8:
case 10: case 12:
totalDays = 31; break;
case 4: case 6: case 9: case 11:
totalDays = 30; break;
case 2:
if( (year % 4 == 0 && year % 100 != 0)
|| year % 400 == 0)
{
totalDays = 29; // 윤년
}
else
{
totalDays = 28; // 평년
}
// year 가 4의 배수이면 윤년
// 그런데, year가 100의 배수이면 평년
// 그런데, year가 400의 배수이면 윤년
// 2003 : 평년
// 2004 : 윤년
// 2100 : 평년
// 2400 : 윤년
}
System.out.println("총 "
+ totalDays + "일 입니다.");
}
}