導航:首頁 > 編程語言 > java列印日歷

java列印日歷

發布時間:2022-06-04 15:56:33

A. 輸入某年某月 列印出當月日歷,要求日期和星期對應,用java語言

import java.util.*;

public class riqi {
public static void main(String[] args) {
int totaldays = 0;
int dayofmonth = 0;
int twomonth;
Scanner input = new Scanner(System.in);
System.out.print("請輸入年份:");
int year = input.nextInt(); // 輸入年份
System.out.print("請輸入月份:");
int month = input.nextInt(); // 輸入月份
for (int i = 1900; i < year; i++) {
if (((i % 4 == 0) && (i % 100 != 0)) || (i % 400 == 0)) {
totaldays = totaldays + 366;
} else {
totaldays = totaldays + 365;
}
}
for (int nomonth = 1; nomonth <= month; nomonth++) {
if (nomonth == 1 || nomonth == 3 || nomonth == 5 || nomonth == 7
|| nomonth == 8 || nomonth == 10 || nomonth == 12) {
dayofmonth = 31;
} else if (nomonth == 2) {
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) {
dayofmonth = 29;
} else {
dayofmonth = 28;
}
} else {
dayofmonth = 30;
}
if (nomonth < month) {
totaldays = totaldays + dayofmonth;
}
// System.out.println(totaldays);
}

System.out.println("星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期天");
int temp = (totaldays % 7);
// System.out.print(temp);
for (int p = 0; p < temp; p++) {
System.out.print("\t");

}
for (int w = 1; w <= dayofmonth; w++) {
System.out.print(w + "\t");
if ((totaldays + w) % 7 == 0) {
System.out.println();
}
}

}

}

B. 關於java中輸出日歷

Calendar c=Calendar.getInstance();//表示獲取當前系統得時間對象;
c.set(Calendar.YEAR, year);//給對應的欄位設置值,即設置年份,以下同理
c.set(Calendar.MONTH, month-1);
c.set(Calendar.DAY_OF_MONTH, day);

C. Java 列印兩個月的日歷


來個一年的,兩個月並排。要是改成顯示僅要兩個月的,也不難。代碼不長,不多解釋了。

D. Java列印日歷

這么無聊的要求、、、

E. 在Java中如何用calendar類輸入年和月份列印當月的日歷

51自學網有教程 詳細的 網路下就好

閱讀全文

與java列印日歷相關的資料

熱點內容
網站怎麼用本地伺服器 瀏覽:118
javadoc導入android 瀏覽:515
文件掃描成pdf 瀏覽:696
涼山火災救援命令 瀏覽:50
壓縮機三相檢測 瀏覽:859
linux怎麼安裝光碟 瀏覽:797
寬頻伺服器無響應是為什麼 瀏覽:224
壓縮包內看圖 瀏覽:912
安卓手機如何發現app後台調用情況 瀏覽:559
程序員簡歷工作描述 瀏覽:157
伺服器中強制疾跑的指令是什麼 瀏覽:52
日語命令性 瀏覽:259
免費的程序編譯游戲 瀏覽:890
如何安裝屏蔽的APP 瀏覽:196
豬臉識別app如何下載 瀏覽:154
卓嵐串口伺服器如何使用 瀏覽:438
pdf周振甫 瀏覽:757
程序員35歲生日圖片 瀏覽:626
矩形密封圈的壓縮量 瀏覽:455
信息安全中圖像加密技術畢業論文 瀏覽:536