牛客——华为笔试合集之HJ73

计算日期到天数转换

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

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while (sc.hasNext()) {
        String[] s = sc.nextLine().split(" ");
        int year = Integer.valueOf(s[0]);
        int month = Integer.valueOf(s[1]);
        int day = Integer.valueOf(s[2]);
        int Feb = 28;
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { //判断闰年
            Feb = 29;
        }
        int[] arr = {31,Feb,31,30,31,30,31,31,30,31,30,31};
        int sumDay = 0;
        for (int i = 0; i < month - 1; i++) {
            sumDay += arr[i];
        }
        sumDay += day;

        System.out.println(sumDay);

    }
    sc.close();

}

}

全部评论

相关推荐

05-19 15:21
已编辑
华南农业大学 Java
白火同学:你才沟通了200,说实话,北上广深杭这里面你连一座城市的互联网公司都没投满呢,更别说还有各种准一线二线城市了。等你沟通突破了三位数,还没结果再考虑转行的事吧。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
05-28 12:15
点赞 评论 收藏
分享
评论
2
3
分享

创作者周榜

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