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

计算日期到天数转换

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);
			}
				
		}

	}
}


#在线刷题#
全部评论

相关推荐

09-13 08:41
服装/纺织设计
那一天的Java_J...:你第一次参加面试吗
点赞 评论 收藏
分享
10-19 14:15
兰州大学 Java
黄花菜豆:咱俩bg很一致啊uu而且我也做过这个仿小红书,感觉有点太深了短期内不好驾驭啊怕被问穿
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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