本题要求实现一个方法,用户输入年代和月份,方法输出当月日历。
注:相关打印设置为:System.out.print(" “); //打印1号前的空档,空1天打印1次;
System.out.printf(”%4d",i); //打印具体日期;
一个月打印完了以后换行。
函数接口定义:
详见主方法中的调用。
裁判测试程序样例:
在这里给出函数被调用进行测试的例子。例如:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int year=input.nextInt();
int month = input.nextInt();
printMonth(year, month);
input.close();
}
public static void printMonth(int year, int month){
printMonthTitle(year, month);
printMonthBody(year, month);
}
public static void printMonthTitle(int year, int month){
System.out.println(" “+getMonthName(month)+ " " + year);
System.out.println(”-----------------------------");
System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
}
/* 请在这里填写答案 */
}
输入样例:
在这里给出一组输入。例如:
2020
9
输出样例:
在这里给出相应的输出。例如:
September 2020 ----------------------------- Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
static void printMonthBody(int year,int month) {
int count=0;
int first=getStartDay(year,month);
for(int i=1;i<=first;++i) {
System.out.print(" ");
}
count+=<