试题 算法训练 天数计算

试题 算法训练 天数计算

在这里插入图片描述在这里插入图片描述

import java.util.Scanner;

public class count {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根

		//【统计生日天数】
		Scanner sc=new Scanner(System.in);
		int year = sc.nextInt();
		int month = sc.nextInt();
		int day = sc.nextInt();
		
		sc.close();
		int SumDays=0;

		for(int i=1;i<month;i++) {
			//31天的
			if((i==1)||(i==3) || (i==5) || (i==7)||(i==8)|| (i==10) || (i==12)) {
				SumDays+=31;
			}else if(i==2) {
				//判断闰年
				if((year%4==0 && year%100!=0) || year%400==0) {
					SumDays+=29;
				}else {
					SumDays+=28;
				}
			}else {
				SumDays+=30; //30天的
			}
		}
		System.out.print(SumDays+day);  
	}

}
发布了16 篇原创文章 · 获赞 0 · 访问量 142

猜你喜欢

转载自blog.csdn.net/qq_43530597/article/details/105029728