题解 | #计算日期到天数转换#

计算日期到天数转换

https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
   public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		while (in.hasNextInt()) {
			int a = in.nextInt();
			int b = in.nextInt();
			int c = in.nextInt();
			int month =0; 
			int[] day = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
			int[] day2 = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
			if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0) {
				for(int i=0;i<b;i++) {
					month += day2[i];
				}
				System.out.println(month + c);
			}
				
			else {
				for(int i=0;i<b;i++) {
					month += day[i];
				}
				System.out.println(month + c);
			}
				
		}

	}
}


#在线刷题#
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务