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

计算日期到天数转换

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

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] ymd = scan.nextLine().split(" ");
        int year = Integer.valueOf(ymd[0].trim());
        int month = Integer.valueOf(ymd[1].trim());
        int day = Integer.valueOf(ymd[2].trim());
        int ans = 0;
        if (month > 1) {
            ans += 31;
        }
        if (month > 2) {
            if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
                ans += 29;
            } else {
                ans += 28;
            }
        }
        if (month > 3) {
            ans += 31;
        }
        if (month > 4) {
            ans += 30;
        }
        if (month > 5) {
            ans += 31;
        }
        if (month > 6) {
            ans += 30;
        }
        if (month > 7) {
            ans += 31;
        }
        if (month > 8) {
            ans += 31;
        }
        if (month > 9) {
            ans += 30;
        }
        if (month > 10) {
            ans += 31;
        }
        if (month > 11) {
            ans += 30;
        }
        ans += day;
        System.out.println(ans);
    }
}
全部评论
该牛油正在参与牛客写题解薅羊毛的活动,牛币,周边,京东卡超多奖品放送,活动进入倒计时!快来捡漏啦https://www.nowcoder.com/discuss/888949?source_id=profile_create_nctrack&channel=-1
点赞 回复 分享
发布于 2022-04-27 11:41

相关推荐

Southyeung:我说一下我的看法(有冒犯实属抱歉):(1)简历不太美观,给我一种看都不想看的感觉,感觉字体还是排版问题;(2)numpy就一个基础包,机器学习算法是什么鬼?我感觉你把svm那些写上去都要好一点。(2)课程不要写,没人看,换成获奖经历;(3)项目太少了,至少2-3个,是在不行把网上学习的也写上去。
点赞 评论 收藏
分享
评论
3
1
分享

创作者周榜

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