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

import java.util.Calendar;
import java.util.Scanner;
import java.time.*;
import java.time.temporal.TemporalAdjusters;
// import java.time.Month;
// import java
public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int year = console.nextInt();

        //write your code here......
        for (int i = 1; i <= 12 ; i++) {
            Month month = Month.of(i);
            LocalDate localDate = LocalDate.of(year, month, 1);
            System.out.println(year + "年" + i + "月" +":"+ localDate.with(
                                   TemporalAdjusters.lastDayOfMonth()).getDayOfMonth() + "天");
//            System.out.println(year+"年"+month+"月:"+calendar.getActualMaximum(Calendar.DATE)+"天");
        }

    }
}

全部评论

相关推荐

06-04 09:27
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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