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

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

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

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......
    Calendar calendar=Calendar.getInstance();
    for(int month=1;month<=12;month++){
        calendar.set(year,month,0);//写入年月参数
        //获取当月天数
        System.out.println(year+"年"+month+"月:"+calendar.get(calendar.DAY_OF_MONTH)+"天");
    }

}

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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