- 最後登錄
- 2023-4-28
- 在線時間
- 0 小時
- 註冊時間
- 2015-11-14
- 閱讀權限
- 10
- 精華
- 0
- UID
- 1260900
- 帖子
- 0
- 積分
- 0 點
- 潛水值
- 190 米
| 分享使你變得更實在,可以使其他人感到快樂,分享是我們的動力。今天就來分享你的資訊、圖片或檔案吧。 public class year {
/**
* Creates a new instance of <code>year</code>.
*/
public year() {
}
/**
* @param args the command line arguments
*/
// TODO code application logic here
public static void main(String[] args)
throws IOException{
String str,Imonth[]={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
int Iyear,two,t_d,w_1,i,day=0,j, month_day;
BufferedReader br =new
BufferedReader(new InputStreamReader(System.in));
System.out.println("請輸入西元年:");
System.out.println("→");
str = br.readLine();
Iyear=Integer.parseInt(str);
if (Iyear%4000==0)
two=28; //two表示二月之天數
else if (Iyear%400==0)
two=29;
else if (Iyear%100==0)
two=28;
else if (Iyear%4==0)
two=29;
else
two=28;
t_d=365*(Iyear-1)+(Iyear-1)/400-(Iyear-1)/4000+(Iyear-1)/4-(Iyear-1)/100+1; // t_d表示元年~輸入年年底+1天數 ;t_d=365*(Iyear-1)+(Iyear-1)/400-(Iyear-1)/100+(Iyear-1)/4+1;
w_1=t_d%7; //w_1表示輸入年的1月1日星期幾
System.out.println("西元"+Iyear+"年一月一日是星期"+w_1);
for (j=0;j<=11;j++)
{
System.out.println();
System.out.println(Imonth[j]);
System.out.println("日 一 二 三 四 五 六");
for(i=1;i<=w_1;i++)// 空格
System.out.print(" ");
day=w_1;
switch(j) //判斷該月幾天
{
case 0: case 2: case 4: case 6: case 7: case 9: case 11: month_day = 31; break;
case 1: month_day = two; break;//index1表示二月
default: month_day = 30;
}
for (i=1;i<=month_day;i++) //列印天數排列正常
{
switch(i){
case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9:
System.out.print(" ");
}
System.out.print(i+" ");//day為計次變數
day++;
if (day==7) //換行列印
{
System.out.println(" ");
day=0;
}
}
w_1 = day; //表下個月一日的位置
}
System.out.println();... |
|