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

计算日期到天数转换

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

import java.util.Scanner;

import java.util.HashMap;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        HashMap<Integer, Integer> map = new HashMap<>();
        map.put(0, 0);
        map.put(1, 31);
        map.put(3, 31);
        map.put(5, 31);
        map.put(7, 31);
        map.put(8, 31);
        map.put(10, 31);
        map.put(12, 31);
        map.put(4, 30);
        map.put(6, 30);
        map.put(9, 30);
        map.put(11, 30);
        int res = 0;
        if ((a % 4 == 0) && (a % 100 != 0) || (a % 400 == 0)) {
            map.put(2, 29);
        } else {
            map.put(2, 28);
        }
        for (int i = 1; i < b; i++) {
            res += map.get(i);
        }
        System.out.println(res + c);
    }
}

全部评论

相关推荐

06-22 10:41
赣东学院 Java
程序员小白条:?周六晚上投,这是什么操作,专门找996起步的吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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