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

计算日期到天数转换

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

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] arr = str.split(" ");
        int year = Integer.valueOf(arr[0]);
        int month = Integer.valueOf(arr[1]);
        int day = Integer.valueOf(arr[2]);
        int num = 0;
        for (int i = 1; i < month; i++) {
            num = num + 31;
            if (i == 4 || i == 6 || i == 9 || i == 11) {
                num = num - 1;
            }
            if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                if (i == 2) {
                    num = num - 2;
                }
            } else {
                if (i == 2) {
                    num = num - 3;
                }
            }
        }
        System.out.print(num + day);
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
08-01 18:00
点赞 评论 收藏
分享
07-29 13:49
深圳大学 运营
字节我爱你
JamesGosli...:秋招还是实习啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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