题解 | #Where in 和Not in#

计算日期到天数转换

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

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader;

public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str; while ((str = br.readLine()) != null) { String[] data = str.split(" "); int year = Integer.parseInt(data[0]); int mouth = Integer.parseInt(data[1]); int day = Integer.parseInt(data[2]);

        int[] arr = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};

        if(year % 100 == 0 && year % 400 ==0 && mouth > 2) {
            System.out.println(arr[mouth - 1] + day + 1);
        } else if (year % 100 != 0 && year % 4==0) {
            System.out.println(arr[mouth - 1] + day + 1);
        } else {
            System.out.println(arr[mouth - 1] + day);
        }


    }
}

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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