万年历
来源:互联网 发布:软件系统开发评估 编辑:程序博客网 时间:2024/06/18 17:24
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
//根据日历类对象的方法,实例化一个当前的日历类对象
Calendar calendar=Calendar.getInstance();
System.out.println("<<<<<<<<<<<<<<<<万年历>>>>>>>>>>>>>>>>>>");
int year=0;
int month=0;
System.out.print("请输入年份:");
year=scanner.nextInt();
System.out.print("请输入月份:");
month=scanner.nextInt();
System.out.println("*********************************************************");
//设置日历对象的年月日
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month-1);//月份是0-11
calendar.set(Calendar.DATE, 1);
//得到当前月份的最大值
int day=calendar.getActualMaximum(Calendar.DATE);
//得到本月中的第一天是星期几
int week=calendar.get(Calendar.DAY_OF_WEEK);
int count=0;//一个计数的变量
System.out.println("\n\t\t"+year+" 年 "+month+" 月\n");
//打印日历的星期
String strDate[]={"星期日\t","星期一\t","星期二\t","星期三\t","星期四\t","星期五\t","星期六\t"};
for (int i = 0; i < strDate.length; i++) {
System.out.print(strDate[i]);
}
System.out.println();
//判断第一天对应的是星期几
while (count<week-1) {
System.out.print("\t");
count++;//计数变量自增
}
//循环打印日历
for (int i = 1; i <= day; i++,count++) {
if (count%7==0) {
System.out.println();
}
System.out.print(i+"\t");
}
//打个换行
System.out.println();
System.out.println();
System.out.println("*********************************************************");
}
Scanner scanner=new Scanner(System.in);
//根据日历类对象的方法,实例化一个当前的日历类对象
Calendar calendar=Calendar.getInstance();
System.out.println("<<<<<<<<<<<<<<<<万年历>>>>>>>>>>>>>>>>>>");
int year=0;
int month=0;
System.out.print("请输入年份:");
year=scanner.nextInt();
System.out.print("请输入月份:");
month=scanner.nextInt();
System.out.println("*********************************************************");
//设置日历对象的年月日
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month-1);//月份是0-11
calendar.set(Calendar.DATE, 1);
//得到当前月份的最大值
int day=calendar.getActualMaximum(Calendar.DATE);
//得到本月中的第一天是星期几
int week=calendar.get(Calendar.DAY_OF_WEEK);
int count=0;//一个计数的变量
System.out.println("\n\t\t"+year+" 年 "+month+" 月\n");
//打印日历的星期
String strDate[]={"星期日\t","星期一\t","星期二\t","星期三\t","星期四\t","星期五\t","星期六\t"};
for (int i = 0; i < strDate.length; i++) {
System.out.print(strDate[i]);
}
System.out.println();
//判断第一天对应的是星期几
while (count<week-1) {
System.out.print("\t");
count++;//计数变量自增
}
//循环打印日历
for (int i = 1; i <= day; i++,count++) {
if (count%7==0) {
System.out.println();
}
System.out.print(i+"\t");
}
//打个换行
System.out.println();
System.out.println();
System.out.println("*********************************************************");
}
0 0
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- Android 语言切换(eclipse)
- csu1511——残缺的棋盘(bfs)
- 九度 题目1249:次小生成树
- Mysql 将表结构导入 Powerdesigner ,并将注释作为 name 列
- Java调用阿里SMTP服务器实现邮件发送
- 万年历
- centos7 无法启动网络(service network restart)错误解决办法
- 试水Bilibili/ijkplayer-Android-Demo
- WPF的DataGrid的使用技巧—列宽调整和列排序问题
- 2017年初BAT的JAVA面试题汇集
- Python相关安装集锦(陆续更新)
- 事件驱动IO-tcp
- Coding 没有止境
- android 金额