国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

【Java自學】打印日歷信息

2019-11-14 14:49:37
字體:
來源:轉載
供稿:網友
  1 package codeTask_FangFa;  2 //                                                                            5.34  使用zeller公式,打印某年某月的日歷信息。  3 import java.util.Scanner;  4 public class PRintRiLi {  5        public static void main(String[] args){  6            Scanner input = new Scanner(System.in);  7            System.out.println("請輸入需要打印日歷的年份:");  8            int year = input.nextInt();  9            System.out.println("請輸入需要打印日歷的月份:"); 10            int month = input.nextInt(); 11            printTitle(year,month); 12            printBody(year,month); 13             14        } 15         16        public static void printTitle(int year,int month){                           //第二戰場--頭 17            System.out.println("                                                      日             歷");    18            System.out.println("                            "+getMonth(month)+"                                "+year); 19            System.out.println("        星期日     星期一    星期二    星期三    星期四    星期五    星期六");  20            System.out.println("--------------------------------------------------"); 21        } 22         23        public static String getMonth(int month){                            // 這就不說啥了 24  25            switch(month){ 26            case 1:return "一月"; 27            case 2:return "二月"; 28            case 3:return "三月"; 29            case 4:return "四月"; 30            case 5:return "五月"; 31            case 6:return "六月"; 32            case 7:return "七月"; 33            case 8:return "八月"; 34            case 9:return "九月"; 35            case 10:return "十月"; 36            case 11:return "十一月"; 37            case 12:return "十二月"; 38            } 39            System.out.println("輸入的月份出錯,程序退出!"); 40            System.exit(0); 41            return "-1"; 42        } 43         44        public static void printBody(int year,int month){                                                     //主戰場--可要看仔細了。                     45            int count = getXingQi(year,month);                     46            int nim = getNumberInMonth(year,month);                           // nim  全拼是 number in month. 47            int day = 1;                                                             //每月的日子,從 1 開始。 48            switch (count){ 49            case 0 : count = 1;break; 50            case 1 : count = 2;break; 51            case 2 : count = 3;break; 52            case 3 : count = 4;break; 53            case 4 : count = 5;break; 54            case 5 : count = 6;break; 55            case 6 : count = 7;break; 56            } 57            for(int i =1;i<count;i++){ 58                 System.out.printf("%7s"," "); 59             } 60             while(day<nim){ 61  62                 while(count%7!=0){ 63                     System.out.printf("%7d",day); 64                     if(day==nim) 65                         System.exit(0); 66                     count++; 67                     day++; 68                      69                 } 70                 System.out.printf("%7d/n",day); 71                 count++; 72                 day++; 73  74             } 75  76            } 77  78         79        public static int getXingQi(int year,int month){                                                       //得到某月1號是星期幾。 這里會用到zeller公式。 80            int m = month; 81            if(month == 1){ 82                m = 13; 83                year--; 84            } 85            else if(month ==2){ 86                m = 14; 87                year--; 88            } 89            int d = 1; 90            int c = year/100; 91            int y = year%100; 92            int w1 =  y+y/4+c/4-2*c+26*(m+1)/10+d-1; 93            int w = (w1%7+7)%7; 94            return w ; 95        } 96         97        public static int getNumberInMonth(int year,int month){                                //返回某月共有幾天。 98            if(isRunNian(year)){ 99                switch (month){100                case 1 : return 31;101                case 2 : return  29  ;102                case 3 : return  31  ;103                case 4 : return  30  ;104                case 5 : return  31  ;105                case 6 : return  30  ;106                case 7 : return  31  ;107                case 8 : return  31  ;108                case 9 : return  30  ;109                case 10 : return  31  ;110                case 11: return   30 ;111                case 12 : return  31  ;112                }113            }114            else{115                switch (month){116                case 1 : return 31;117                case 2 : return  28  ;118                case 3 : return  31  ;119                case 4 : return  30  ;120                case 5 : return  31  ;121                case 6 : return  30  ;122                case 7 : return  31  ;123                case 8 : return  31  ;124                case 9 : return  30  ;125                case 10 : return  31  ;126                case 11: return   30 ;127                case 12 : return  31  ;128                }129            }130            return -1;                                                              //錯誤情況下的返回值。131        }132        133        public static boolean isRunNian(int year){                                    //判斷閏年。是就true134            if(year%400==0||(year%4==0&year%100!=0))135                return true;136            return false;137        }138 }

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 北辰区| 遵化市| 凭祥市| 三都| 北辰区| 句容市| 隆子县| 永川市| 钦州市| 宁波市| 沙田区| 休宁县| 延长县| 揭阳市| 渑池县| 安陆市| 公主岭市| 博爱县| 敦煌市| 辽阳县| 永修县| 鄂温| 甘洛县| 渝北区| 保靖县| 许昌市| 湖口县| 仪征市| 从化市| 儋州市| 绍兴市| 耿马| 喜德县| 孟村| 莲花县| 新河县| 互助| 肥东县| 绍兴县| 碌曲县| 万山特区|