日历
2016-05-14 10:40
435 查看
import java.util.Scanner;
public class Date {
public Date(){
Scanner sc = new Scanner(System.in);
System.out.println(“请输入年份: “);
int year = sc.nextInt();
System.out.println(“请输入月份: “);
int month = sc.nextInt();
}
public class Date {
public Date(){
Scanner sc = new Scanner(System.in);
System.out.println(“请输入年份: “);
int year = sc.nextInt();
System.out.println(“请输入月份: “);
int month = sc.nextInt();
int total = 0; for(int i=1900;i<year;i++){ total += getDaysForYear(i); } for(int i=1;i<month;i++){ total += getDays(year,i); } total += 1; int dayofweek = total % 7; int sum = getDays(year,month); System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六"); if(dayofweek != 0){ int sum1; if(month != 1){ sum1 = getDays(year,month-1); }else{ sum1 = getDays(year-1,12);// 31 } int i = sum1 - dayofweek + 1; while(i<=sum1){ System.out.print(i + "\t"); i++; } } for(int i=1;i<=sum;i++){ if(dayofweek == 0 && i == 1){ }else if((i+dayofweek-1)%7 == 0){ System.out.println(); } System.out.print(i + "\t"); } if((dayofweek+sum)%7 != 0){ int sum2 = ((dayofweek+sum)/7+1)*7-(dayofweek+sum); for(int i=1;i<=sum2;i++){ System.out.print(i + "\t"); } } System.out.println(); sc.close(); } public static int getDays(int year,int month){ if(month ==1 ||month ==3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){ return 31; }else if(month == 4 || month == 6 || month == 9 || month == 11){ return 30; }else{ if(isRun(year) == true){ return 29; }else{ return 28; } } } public static int getDaysForYear(int year){ if(isRun(year) == true){ return 366; }else{ return 365; } } private static boolean isRun(int year) { // TODO Auto-generated method stub if(year%4 == 0 && year%100 != 0 || year%400 == 0){ return true; }else{ return false; } }
}
相关文章推荐
- Announcing SyntaxNet: The World’s Most Accurate Parser Goes Open Source
- Java-split函数-分割字符串
- 单链表的反转
- HDU 1017 A Mathematical Curiosity【水题】
- Java千百问_06数据结构(015)_数组和普通对象的引用变量有什么区别
- 最优化学习笔记(二)——二分法
- Provisioning Services 7.8 入门系列教程14篇全部完成了.....
- dijkstra求最短路径(水题)
- ViewPager控件的Demo
- tomcat-在cmd窗口启动Tomcat
- [开发工具]Java开发常用的在线工具
- ntp 时间服务器地址
- Maven编码异常处理
- LeetCode|Contains Duplicate*
- History Grading(uva 111)
- matlab win7 64bit 找不到vs2013编译器解决办法
- HDU1329 Hanoi Tower Troubles Again!——S.B.S.
- 电脑开机都做了哪些工作
- Linux centos编译程序时的性能问题
- Linux centos编译程序时的性能问题