導航:首頁 > 編程語言 > 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列印日歷相關的資料

熱點內容
下載需要解壓的小說用哪個軟體 瀏覽:529
廣東分布式伺服器雲主機 瀏覽:578
伺服器忙打不開怎麼辦 瀏覽:10
tif壓縮軟體 瀏覽:408
程序員那麼可愛陸漓上班第1天 瀏覽:950
macbookair自帶什麼app 瀏覽:696
如何關了加密的軟體 瀏覽:577
程序員p2p待遇 瀏覽:920
ipd編譯要求 瀏覽:931
壓縮解壓王怎麼用 瀏覽:29
伺服器共享文件如何備份 瀏覽:753
買安卓手機怎麼在官網買 瀏覽:122
詩詞入門PDF 瀏覽:361
毒app是什麼單位 瀏覽:64
如何自己編譯android系統 瀏覽:792
phpmysqlpdomysqli 瀏覽:808
php修改sql語句 瀏覽:720
android有道api 瀏覽:388
撓耳營水表用的什麼app 瀏覽:55
戰錘40kpdf 瀏覽:381