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

计算日期到天数转换

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int year = scanner.nextInt();
        int month = scanner.nextInt();
        int day = scanner.nextInt();
        int result = 0;
        ArrayList<Integer> PingList = new ArrayList<>();
        PingList.add(31);
        PingList.add(28);
        PingList.add(31);
        PingList.add(30);
        PingList.add(31);
        PingList.add(30);
        PingList.add(31);
        PingList.add(31);
        PingList.add(30);
        PingList.add(31);
        PingList.add(30);
        PingList.add(31);
        ArrayList<Integer> RunList = new ArrayList<>();
        RunList.add(31);
        RunList.add(29);
        RunList.add(31);
        RunList.add(30);
        RunList.add(31);
        RunList.add(30);
        RunList.add(31);
        RunList.add(31);
        RunList.add(30);
        RunList.add(31);
        RunList.add(30);
        RunList.add(31);
        //闰年
        if (year > 0 && month <= 12 && day <= 31) {
            if (year % 4 == 0&&year % 100 != 0 || year % 400 == 0) {
                for (int i1 = 1; i1 < month; i1++) {
                    result = result + RunList.get(i1 - 1);
                }
                result = result + day;
            } else {
                for (int i1 = 1; i1 < month; i1++) {
                    result = result + PingList.get(i1 - 1);
                }
                result = result + day;
            }
        }
        System.out.println(result);

    }
}
 四年一闰 百年不闰 四百年一闰
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 17:13
想去,但是听说加班强度实在难崩,所以拒绝了,现在有点心梗对面hr感觉也是实习生,打电话的时候怪紧张的,但是感觉人很好嘞
水中水之下水道的鼠鼠:哥们这不先去体验一下,不行再跑呗,大不了混个实习经历(有更好的转正offer就当我没说)
点赞 评论 收藏
分享
_mos_:我以为手抄报简历就已经很顶了,没想到还有表格简历
点赞 评论 收藏
分享
但听说转正率很低,我现在有在实习了,好纠结要不要去
熬夜脱发码农:转正率低归低,但是实习的经历你可以拿着,又不是说秋招不准备了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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