package 作业;
import java.util.Scanner;public class 日历3 { static int year, monthDay, weekDay = 7; public static void main(String[] args) { int yearday=365; // int year; // 年份 int week; // 输入1.1为星期几 int monthday; // 每月天 System.out.print(“请输入年份以及1.1为星期几:”); Scanner scanner =new Scanner(System.in); year = scanner.nextInt(); week = scanner.nextInt(); scanner.close(); // 判断平闰年 if (year%40||year%100!=0||year%4000) { }else { yearday=yearday+1; } for (int i = 1; i <= 12; i++) { // 判断各月天数 if (i1i==3i5i==7i8i==10i12) { monthday=31; }else if (i4i==6i9^i11) { monthday=30; }else if (yearday%20) { monthday=29; }else { monthday=28; } System.out.println("\t"+year+“年”+i+“月”); System.out.println("============================="); System.out.println(" Sun Mon Tue Wed Thu Fri Sat"); print(monthday, week); week = (monthday + week) % weekDay; } } public static void print(int monthDay, int week){ for(int i = 0; i < week; i++) System.out.print(" “); // 判断当前月份空格数 for(int i = 1; i <= monthDay; i++){ // 循环当前月天数 System.out.printf(”%4d", i); // 星期表头与日期对齐 if((i + week) % weekDay == 0) // 星期正常实现换行 System.out.println(); } System.out.println(); // 月份之间的换行,12次 }}
2020-03-20
最新推荐文章于 2021-03-07 23:41:23 发布