?? test4.java
字號:
import java.util.*;//導(dǎo)入Scanner
public class test4 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int day = 0, allday = 0, inputday = 0, aday = 0;
int firstday;
System.out.print("請輸入要查詢的年:");// 提示輸入要查詢的年
int year = input.nextInt();
System.out.print("請輸入要查詢的月:");// 提示輸入要查詢的月
int mouth = input.nextInt();
for (int i = 1; i <= mouth; i++) {
if (i == 1 | i == 3 | i == 5 | i == 7 | i == 8 | i == 10 | i == 12) {
day = 31;
} else if (i == 4 | i == 6 | i == 9 | i == 11) {
day = 30;
} else if (i == 2 && year % 4 == 0 && year % 100 != 0
| year % 400 == 0) {
day = 29;
} else {
day = 28;
}
if (i < mouth) {
inputday = inputday + day;
} // 計算當月距離當年1月的天數(shù)
}
for (int i = 1990; i < year; i++) {
if (i % 4 == 0 && i % 100 != 0 | i % 400 == 0) {
aday = aday + 366; // 計算當年距離1990年的天數(shù)
} else {
aday = aday + 365;
}
}
allday = aday + inputday; // 計算距離1990年的總天數(shù)
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
int temp = 1 + allday % 7; // 從1900年1月1日推算
if (temp == 7) { // 求當月第一天
firstday = 0; // 周日
} else {
firstday = temp;
}
for (int i = 0; i < firstday; i++) {
System.out.print("\t");
}
for (int i = 1; i <= day; i++) {
System.out.print(i + "\t");
if ((allday + i - 1) % 7 == 5) {
System.out.println();
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -