输入某年某月某日,判断这一天是这一年的第几天?

package testaa;

import java.util.Scanner;

public class CountDay {
 public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("输出今年是第几年:");
        int year = scanner.nextInt();
        System.out.print("输出今年是第几月:");
        int month = scanner.nextInt();
        System.out.print("输出今年是第几日:");
        int day = scanner.nextInt();
        int daysum = 0; // 天数
        // 判断 闰年计算方法 口诀:四年一闰,百年不闰,四百年再闰
        int[] month1; //声明数组
        if (year % 400== 0||(year % 4== 0&&year%100!=0)) {
            month1 = new int[]{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        }else{
            month1 = new int[]{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        }

        // 判断这一天是第几天
        for (int i = 1; i <= month; i++) {
            if ( i== 1) {
                daysum = day;
            } else {
                daysum += month1[i - 2];
            }
        }
        System.out.println("这一天是:"+year+"年"+month+"月"+day+"日");
        System.out.println("这一天是这一年的第" + daysum + "天!");
    }

}

你可能感兴趣的:(输入某年某月某日,判断这一天是这一年的第几天?)