본문 바로가기

프로그램공부/java공부

달력 중간저장

package test;

import java.util.Scanner;

public class Calendar {

    public static int re(String day) {
        //String day="a";
        if(day.equals("mo")) {return 1;}
        else if(day.equals("tu")) {return 2;}
        else if(day.equals("we")) {return 3;}
        else if(day.equals("th")) {return 4;}
        else if(day.equals("fr")) {return 5;}
        else if(day.equals("sa")) {return 6;}
        else if(day.equals("su")) {return 7;}
        else return 0;

    }

    private static void mo_fi() {

        System.out.println(" su mo tu we th fr sa");
        System.out.println("---------------------");
    }

    public static void main(String[] args) {

        System.out.println("년을 입력하세요\n year>");
        Scanner scanner = new Scanner(System.in);
        int year = scanner.nextInt();

        System.out.println("월을 입력하세요\n month>");
        int month = scanner.nextInt();

        System.out.println("요일을 입력하세요\n day>");
        String day = scanner.next();
        re(day);
        scanner.close();

        int[] yearDate = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int[] leapYearDate = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

        if (year % 4 == 0 && year % 100 == 0 || year % 400 == 0) {
            mo_fi();
            //first line

            //int count = (7-re(day));

            for(int i=0;i<re(day);i++) {
                System.out.print("   ");                
            }
            for (int i = 1; i <= yearDate[month - 1]; i++) {
                System.out.printf("%3d", i);
                if (i % 7 == 0) {
                    System.out.println();
                }
            }

        } else {
            mo_fi();
            for(int a= 0; a< re(day) ;a++) {
                System.out.print("   ");
            }
            for (int i = 1; i <= leapYearDate[month-1]; i++) {
                    System.out.printf("%3d", i);
                if (i % 7 == 0) {
                    System.out.println();
                }

            }
        }
    }
}