-1
每當星期幾的值爲空時,如何在日曆上顯示' - '?缺少值時插入破折號( - )
下面是代碼:
public static void printCalander(int month, int year) {
String[] monthNames = {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//showing which month is being displayed on the yearly calendar
System.out.println(" " + monthNames[month] + " " + year);
System.out.println("Su Mo Tu We Th Fr Sa");
for (int index = 0; index < obj1; index++) {
System.out.print(" ");
}
//numDays is showing how many days are needed for the calendar following the user input
for (int count = 1; count <= numDays; count++) {
System.out.printf("%2d ", count);
//if the calendar reaches 7 numbers then it will take a new line
if (((count + obj1) % 7 == 0) || (count == numDays)) {
System.out.println("");
}
}//for
}//end of printCalendar