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

计算日期到天数转换

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

相关推荐

不愿透露姓名的神秘牛友
07-09 16:15
我应届生,去年10月份开始在这家公司实习,到今年10月份正好一年想(实习+试用期),在想要不要提前9月份就离职,这样好找工作些,但又差一个月满一年,又怕10月份国庆回来离职,容易错过了下半年的金九银十,到年底容易gap到年后
小破站_程序员YT:说这家公司不好吧,你干了快一年 说这家公司好吧,你刚毕业就想跑路说你不懂行情吧,你怕错过金九银十说 你懂行情吧,校招阶段在实习,毕业社招想换工作 哥们,我该怎么劝你留下来呢
应届生,你找到工作了吗
点赞 评论 收藏
分享
点赞 评论 收藏
分享
06-02 15:17
门头沟学院 Java
心爱的idea:怎么会呢 应该是打招呼有问题 问就说实习6个月全国可飞随时到岗
点赞 评论 收藏
分享
评论
3
1
分享

创作者周榜

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