package com.arraylist.demo2;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
/**
* 案例 打印月份中的天数
* @author 21434
*
*/
public class Demo4 {
public static void main(String[] args) {
// 注意定义的 1 日期不能更改
LocalDate now =LocalDate.of(2001,2,1);
// 获取星期几
int week = now.getDayOfWeek().getValue();
now = now.with(TemporalAdjusters.lastDayOfMonth());
int dayOfMonth = now.getDayOfMonth();
System.out.print("天\t");
System.out.print("一\t");
System.out.print("二\t");
System.out.print("三\t");
System.out.print("四\t");
System.out.print("五\t");
System.out.println("六\t");
for(int i =0;i<week;i++) {
System.out.print("\t");
}
if(week==7) {
System.out.println();
}
// 打印
for(int i =1;i<=dayOfMonth;i++) {
System.out.print(i+"\t");
if((week+i)%7==0) {
System.out.println();
}
}
}
}
效果图