显示日历
来源:互联网 发布:win10无法更改mac地址 编辑:程序博客网 时间:2024/05/21 15:45
编写程序,提示用户输入年份和该年第一天的星期,在控制台上显示该年的日历
表。例如,用户输入2010年,第一天是星期5,则显示如下的日历:
import javax.swing.*;public class Date { public static void main(String[] args) { String yearString = JOptionPane.showInputDialog("Enter a year:"); int year = Integer.parseInt(yearString); String firstDayString = JOptionPane.showInputDialog("Enter the first day of the year:"); int firstDay = Integer.parseInt(firstDayString); int startDay = firstDay; int numberOfDaysInMonth = 0; // Display calendar for each month for (int month = 1; month <= 12; month++) { // Display Calendar title System.out.print(" "); switch (month) { case 1: System.out.println("January " + year); numberOfDaysInMonth = 31; break; case 2: System.out.println("Feburary " + year); if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) numberOfDaysInMonth = 29; else numberOfDaysInMonth = 28; break; case 3: System.out.println("March " + year); numberOfDaysInMonth = 31; break; case 4: System.out.println("April " + year); numberOfDaysInMonth = 30; break; case 5: System.out.println("May " + year); numberOfDaysInMonth = 31; break; case 6: System.out.println("June " + year); numberOfDaysInMonth = 30; break; case 7: System.out.println("July " + year); numberOfDaysInMonth = 31; break; case 8: System.out.println("August " + year); numberOfDaysInMonth = 31; break; case 9: System.out.println("September " + year); numberOfDaysInMonth = 30; break; case 10: System.out.println("October " + year); numberOfDaysInMonth = 31; break; case 11: System.out.println("November " + year); numberOfDaysInMonth = 30; break; case 12: System.out.println("December " + year); numberOfDaysInMonth = 31; break; } System.out.println("-----------------------------"); System.out.println(" Sun Mon Tue Wed Thu Fri Sat"); // Pad space before the first day of the month int i = 0; for (i = 0; i < startDay; i++) System.out.print(" "); for (i = 1; i <= numberOfDaysInMonth; i++) { if (i < 10) System.out.print(" " + i); else System.out.print(" " + i); if ((i + startDay) % 7 == 0) System.out.println(); } System.out.println(); System.out.println(); // Get the start day for the next month startDay = (startDay + numberOfDaysInMonth) % 7; } }}
0 0
- 日历显示
- 显示日历
- 显示日历
- 显示日历
- 显示日历
- cal命令(显示日历)
- CalendarExtender 日历显示中文
- WP7显示日历天气
- 显示日历和天气
- 显示日历控件代码
- Flex日历中文显示
- yii 日历分秒显示
- java_calendar日历的显示
- 显示本月日历
- java实现日历显示
- Linux cal --显示日历
- cal 显示日历
- 弹出dialog显示日历
- 1001.A+B Format (20)
- HTML标签之常见表单标签
- centos6.6搭建apache+mysql+php环境(2)
- 更改tomcat服务器项目的图标
- sduacm16级寒假热身
- 显示日历
- 假期训练——OpenJ_Bailian - 4017 爬楼梯 动态规划
- 360全景实现
- Ubuntu安装和配置Java环境
- 显示一个饼图
- ARM之2440内存初始化
- opencv读取、显示、保存图像
- 显示一个井字游戏的棋盘
- JavaScript+Jquery