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

首頁 > 編程 > Java > 正文

用java實(shí)現(xiàn)打印日歷的方法

2019-11-06 08:54:38
字體:
供稿:網(wǎng)友

java實(shí)現(xiàn)打印日歷的方法

* 打印2016年的日歷方法*/public static void PRintCalendar(){for (int i = 1; i <= 12; i++) {System.out.println("2016年"+i+"月");System.out.println("-------------------------------------");System.out.println("日/t一/t二/t三/t四/t五/t六");int days = getDays(i);//得到第i月有多少天for(int j = 1 ; j <= days ; j++){int numDay = getNumDay(i, j);//得到i月j號是2016年第幾天int week = getWek(numDay);//得到i月j號是周幾if(j==1){//號數(shù)是一號的時(shí)候String temp = "";//補(bǔ)空位的字符串for (int k = 0; k < week; k++) {temp = temp+"/t";}if(week == 6){//如果1號是周六。輸出以后就要換行System.out.println(temp+j);}else{//如果不是,就不需要了System.out.print(temp+j+"/t");}}else if(week == 6|| j == days){//不是一號但是是周六或者是該月的最后一天,輸出以后就要換行System.out.println(j);}else{//就不是周六也不是一號也不是該月最后一天System.out.print(j+"/t");}}System.out.println("*****************************************");}}/*** 根據(jù)該天是這一年的第幾天,得到這一天是周幾* @param numDay 這一年的第幾天* @return 周幾*/public static int getWek(int numDay){switch(numDay%7){case 1:return 5;case 2:return 6;case 3:return 0;case 4:return 1;case 5:return 2;case 6:return 3;case 0:return 4;}return 0;}/*** 根據(jù)輸入的幾月幾號,得到這一天是這一年的第幾天* @param month 幾月* @param date 幾號* @return 第幾天*///5 10public static int getNumDay(int month,int date){int numDay=0;//天數(shù)//將指定的月份前幾個(gè)月的天數(shù)累加for (int i = 1; i < month; i++) {int days = getDays(i);//賦值調(diào)用,得到第i月的天數(shù)numDay = numDay + days;}//將指定的天數(shù)加起來numDay = numDay+date;return numDay;}/*** 根據(jù)輸入的月份得到該月的天數(shù)* * @param month 輸入的月份* @return 該月的天數(shù)*/public static int getDays(int month) {switch (month) {case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;case 4:case 6:case 9:case 11:return 30;case 2:return 29;}return 0;}}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 荣成市| 高邑县| 孟津县| 朝阳市| 大洼县| 玉溪市| 改则县| 昔阳县| 阜新市| 汽车| 始兴县| 新田县| 滕州市| 曲麻莱县| 贵阳市| 邵东县| 枣庄市| 田林县| 娄烦县| 资兴市| 河东区| 余江县| 丰顺县| 华宁县| 兴文县| 东方市| 新余市| 道真| 库尔勒市| 东阿县| 达尔| 开平市| 呼伦贝尔市| 西乡县| 洪泽县| 颍上县| 阳信县| 房山区| 易门县| 祁门县| 霍山县|