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

import java.util.Scanner;
import java.util.TreeMap;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            int year = in.nextInt();
            int month=in.nextInt();
            int day=in.nextInt();
            TreeMap<Integer,Integer> map=new TreeMap<>();
            map.put(1,31);
            map.put(3,31);
            map.put(4,30);
            map.put(5,31);
            map.put(6,30);
            map.put(7,31);
            map.put(8,31);
            map.put(9,30);
            map.put(10,31);
            map.put(11,30);
            map.put(12,31);
            if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)){
                map.put(2,29);
                for(Integer m:map.keySet()){
                    if(month>m){
                        day=day+map.get(m);
                    }
                }
            }else{
                map.put(2,28);
                for(Integer m:map.keySet()){
                    if(month>m){
                        day=day+map.get(m);
                    }
                }
            }
            System.out.println(day);
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
找工作时遇到的神仙HR
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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