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

计算日期到天数转换

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


import java.util.Scanner;



public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            String time = in.nextLine();
            String[] s = time.split(" ");
            int[] arr = new int[s.length];
            for (int i = 0; i < s.length; i++) {
                arr[i] = Integer.parseInt(s[i]);
            }
            int[] mouthDay = {31,28,31,30,31,30,31,31,30,31,30,31};
            if (checkYear(arr[0])){
                mouthDay[1] = 29;
            }
            int count = 0;
            for (int i = 0; i < arr[1]-1; i++) {
                count = mouthDay[i] +count;
            }
            count = count + arr[2];
            System.out.println(count);
        }
    }
    public static boolean checkYear(int year){
        if (year%400 == 0 ){
            return true;
        }
        if (year%4 == 0 && year % 100 != 0){
            return true;
        }

        return false;
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
LastWh1spe...:ssob真有些人和那个没睡醒一样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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