首页 > 其他 > 详细

日历源代码

时间:2014-08-15 20:59:39      阅读:389      评论:0      收藏:0      [点我收藏+]

 

  1: import java.util.*;
  2: public class rili {
  3:   public static void main(String[] args) {
  4:     int k=0;
  5:     Scanner in= new Scanner(System.in);
  6:     System.out.print("请输入年份:");
  7:     int year=in.nextInt();
  8:     System.out.print("请输入月份:");
  9:     int month=in.nextInt();
 10:     int sum=0;
 11:     for(int i=1900;i<year;i++){
 12:       if(i%4==0&&i%100!=0||i%400==0){
 13:         sum+=366;
 14:       }else{
 15:         sum+=365;
 16:       }
 17:     }
 18:     for(int i=1;i<month;i++){
 19:       if(i==2){
 20:         if(year%4==0&year%100!=0||year%400==0){
 21:           sum+=29;
 22:         }else{
 23:           sum+=28;
 24:         }
 25:       }else if(i==4||i==6||i==9||i==11){
 26:         sum+=30;
 27:         }else{
 28:         sum+=31;        
 29:       }
 30:     }  
 31:     sum+=1;
 32:     if(month==2&&(year%4==0&year%100!=0||year%400==0)){
 33:       k=29;
 34:     }else if(month==4||month==6||month==9||month==11){
 35:       k=30;
 36:     }else{
 37:       k=31;
 38:     }
 39:     System.out.println("日\t一\t二\t三\t四\t五\t六");
 40:     int wekday=sum%7;
 41:     for(int i=1;i<=wekday;i++){
 42:       System.out.print("\t");
 43:     }
 44:     for(int i=1;i<=k;i++,sum++){
 45:       if(sum%7==6){
 46:         System.out.print(i+"\n");
 47:       }else{
 48:         System.out.print(i+"\t");
 49:       }
 50:     }
 51:   }
 52: }

 

bubuko.com,布布扣

日历源代码,布布扣,bubuko.com

日历源代码

原文:http://www.cnblogs.com/javalittleman/p/3915595.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!