【发布时间】:2019-09-08 01:59:40
【问题描述】:
我正在尝试制作日历,这部分代码应该打印日期。
现在,当日历完成时,行“|”停在最后一天。
31 旁边的框应该有一行。
这是我目前所拥有的。
System.out.println("+-----------------------------------------+");
System.out.println("| " + months[month] + " " + year + " |");
System.out.println("+-----------------------------------------+");
System.out.println("| Sun | Mon | Tue | Wed | Thu | Fri | Sat |");
System.out.println("+-----------------------------------------+");
int d = day(month, 1, year);
// printing the days
for (int i = 0; i < d; i++)
System.out.print("| ");
for (int i = 1; i <= days[month]; i++) {
System.out.printf("| %2d", i);
if (((i + d) % 7 == 0) || (i == days[month])) System.out.println("|" + "\n" + "| | | | | | | |" + "\n" + "+-----+-----+-----+-----+-----+-----+-----+");
}
}
}
Expected Output (Bottom part)
+-----+-----+-----+-----+-----+-----+-----+
| 26 | 27 | 28 | 29 | 30 | 31 | |
| | | | | | | |
+-----+-----+-----+-----+-----+-----+-----+
Actual Output (Bottom part)
+-----+-----+-----+-----+-----+-----+-----+
| 26| 27| 28| 29| 30| 31|
| | | | | | | |
+-----+-----+-----+-----+-----+-----+-----+
【问题讨论】:
标签: java calendar monthcalendar