import java.util.*; class demo2 { public static void main(String[] args) { System.out.println("---------日历------------"); Scanner input =new Scanner(System.in); System.out.println("输入年份"); int year = input.nextInt(); System.out.println("输入月份"); int month = input.nextInt(); int sumDay=0; int monthDay=0; for(int i=1900;i<year;i++) { sumDay+=365; if(month==2){ monthDay=28; } else { if(month==4||month==6||month==9||month==11){ monthDay=30; }else{ monthDay=31; } } } for(int i=1;i<month;i++){ if(i==2){ if(year%4==0&&year%100!=0||year%400==0){ sumDay+=29; }else{ sumDay+=28; } } else { if(i==4||i==6||i==9||i==11){ sumDay+=30; }else{ sumDay+=31; } } } System.out.println("一共有"+sumDay+"天"); //计算month月的第一天为周 几 int weekday =(sumDay+1)%7; System.out.println(weekday); System.out.println("星期天 星期一 星期二 星期三 星期四 星期五 星期六"); for(int a = 0;a<weekday;a++){ System.out.print(" "); } for(int b=1; b<=monthDay;b++){ System.out.print(b+" "); if(( b+weekday)%7 ==0) System.out.println(); } } }