package com.lovcoding.day05.arrex;

import java.util.Scanner;

public class Test01 {
    public static void main(String[] args) {
        //已知平年12个月每个月的总天数是{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31}，
        // 从键盘输入年，月，日后，计算这一天是这一年的第几天。提示：考虑闰年
        //考虑输入合法行
        Scanner scanner = new Scanner(System.in);
        System.out.println("年");
        int year;
        while (true){
            year = scanner.nextInt();
            if (year > 2022){
                break;
            }else{
                System.out.println("请输入大于2022的年份");
            }
        }

        System.out.println("月");
        int month;
        while (true){
            month = scanner.nextInt();
            if (month >= 0 && month <=12 ){
                break;
            }else{
                System.out.println("请输入合法的月份");
            }
        }

        //根据月份设置天数
        int monthOfDays;
        if (month == 2){
            if( year % 4 == 0 && year % 400 == 0 || year % 100 == 0){
                monthOfDays = 29;
            }else{
                monthOfDays = 28;
            }
        }else if( month == 4 || month == 6 || month == 8 || month == 11){
            monthOfDays = 30;
        }else{
            monthOfDays = 31;
        }

        System.out.println("日");
        int day;
        while (true){
            day = scanner.nextInt();
            if ( day <= 0 ){
                System.out.println("日期大于0");
            }else if (day > monthOfDays){
                System.out.println(year+"年"+month+"月 ,只有"+monthOfDays+"天");
            }else{
                break;
            }
        }

        int days = 0;
        //月份 数组
        int[] ms = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31};
        //判断闰年
        if( year % 4 == 0 && year % 400 == 0 || year % 100 == 0){
            days++;
        }
        //根据月份 天数
        for (int i = 0; i < month-1 ; i++) {
            days+= ms[i];
        }
        //天数+
        days+=day;

        System.out.println("days="+days);

    }
}
