Programming/JAVA,JSP

JAVA Calendar #2

TanSanC 2013. 12. 31. 16:58

import java.util.Scanner;

 

public class Calendar {

   public static void main(String args[]) {

 

       int year;

       int month;

       int totalDays = 0;

       int totalYearDays = 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 : 윤년

       }

      

       // 해당 년도의 총 일수

       if( (year % 4 == 0 && year % 100 != 0)

             || year % 400 == 0)

       {

          // 366

       }

       else

       {

          // 365

       } 

      

       // 해당 년도의 1 1일의 요일 구하기

       // 기준점 : 1900 1 1일 월

       // totalYearDays 에 저장하라.

       // 2000 1 1

      

       System.out.println("월 화 수 목 금 토 일");

       System.out.println("1900 1 1일 부터 "

             +year +" 1 1일 까지는 총 "

             +totalYearDays + "일이 지났습니다.");

      

   }

}