题解 | #输出某一年的各个月份的天数#

输出某一年的各个月份的天数

http://www.nowcoder.com/practice/6cc6d87805cc4e32866be0541998d8c9

1、先存平年的每月天数 2、如果是闰年再修改即可

import java.util.Calendar;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int year = console.nextInt();

        //write your code here......
        int[] month = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};  // 一年的月天数
        // 如果是闰年就特殊处理
        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
            month[1] = 29;
        }
        for (int i = 1; i <= month.length; i++) {
            System.out.println(year + "年" + i + "月:" + month[i-1] + "天");
        }

    }
}
全部评论

相关推荐

notbeentak...:真的nc,算毕业6月份,要给这种b公司打半年多白工😅
点赞 评论 收藏
分享
10-28 17:30
已编辑
华东交通大学 Java
iori2333:这太正常了 我字节面了四五轮 没有一次是在官网投递 都是hr主动捞
秋招笔试记录
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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