台灣最大程式設計社群網站
線上人數
1832
 
會員總數:245248
討論主題:189105
歡迎您免費加入會員
討論區列表 >> Java >> JAVA萬年曆
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
JAVA萬年曆
價值 : 20 QP  點閱數:7462 回應數:5

樓主

小咪
初學者
40 66
854 79
發送站內信

這個萬年曆的程式...我看不太懂...有人可以幫我註解嗎??
import java.util.*;
import java.io.*;


public class year{
//使用多載函數
private static String myPath, myFileData;
public static void main(String[] args) throws IOException {

System.out.println(year.ShowDate(2006,1));


System.out.println("\t\t***歡迎使用真好用行事曆***");
System.out.println("請選擇功能選項:");
System.out.print("1.萬年曆 2.行事曆 3.Memo記事 (輸入9999 -->結束此程式) -->");

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
int choose = Integer.parseInt(str);
switch(choose){
case 1:
System.out.print("\n\n");
System.out.println("\t\t您現在使用的是-->萬年曆功能");
System.out.println(year.ShowDate(2006,1));
System.out.println("\n請選擇以下選項");
System.out.print("輸入1 -->輸出一整年,輸入2 -->輸出一個月,輸入9999 -->結束此程式: ");

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int x=Integer.parseInt(in.readLine());
int y=0;
while(x!=9999){
if(x == 1){
System.out.print("\n 請輸入年份(輸入9999-->結束此程式):");
x=Integer.parseInt(in.readLine());
if(x==9999) break;
System.out.print("\n 月份務必key 0 此數 (輸入9999-->結束此選項):");
y=Integer.parseInt(in.readLine());
if(x != 9999 && y==0)
System.out.println(year.ShowDate(x));

else { System.out.println("");
System.out.println("因選擇印<一整年>,故請key 0 !");}

}
if(x == 2){
System.out.print("\n 請輸入年份(輸入9999-->結束此選項):");
x=Integer.parseInt(in.readLine());
if(x == 9999){
x=-1;y=-1;
continue;
}
System.out.print("\n 請輸入月份(輸入9999-->結束此選項):");
y=Integer.parseInt(in.readLine());
if(y == 9999){
x=-1;y=-1;
continue;
}else{
for(int z=1;z<=15;z++){
if(y<0 || y>12){
System.out.print("\n 無效的月份");
System.out.print("\n 請再輸入月份(輸入9999-->結束此選項):");
y=Integer.parseInt(in.readLine());
}
}
}

System.out.println(year.ShowDate(x,y));
}if(x == 9999)break;
System.out.print("\n"+"*************************************************************************"+"\n");
System.out.println("輸入錯誤!");
System.out.println("請重新選擇以下選項");
System.out.print("輸入1 -->輸出一整年,輸入2 -->輸出一個月,輸入9999 -->結束此程式:");
x=Integer.parseInt(in.readLine());

}break;


public static String ShowDate(int yer,int mon){
int daye[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int beginday=1,lostdat=0;
String ShowMessage="";

//閏年判斷&置換
if (mon == 2)
if ((yer % 400 == 0) || ((yer % 4 == 0) && (yer % 100 != 0)))
daye[1] = 29;
else
daye[1] = 28;

Calendar ShowT = new GregorianCalendar();
ShowT.set(yer,mon-1,1);

ShowMessage+="\n"+"\t\t\t" + yer + "年" + mon + "月" + "\n";
ShowMessage+="日\t一\t二\t三\t四\t五\t六\n";

if (((ShowT.get(Calendar.DAY_OF_WEEK)-1)+daye[mon-1])%7 != 0)
lostdat = 1;

for(int i = 1;i<= ((ShowT.get(Calendar.DAY_OF_WEEK)-1)+daye[mon-1])/7+lostdat ;i++)
{
for(int j = 1;j<=7;j++)
{
if(beginday <= (ShowT.get(Calendar.DAY_OF_WEEK)-1) || beginday > daye[mon-1] + (ShowT.get(Calendar.DAY_OF_WEEK)-1))
ShowMessage+="\t";
else
ShowMessage+=(beginday-(ShowT.get(Calendar.DAY_OF_WEEK)-1)) +"\t";
beginday++;
}
ShowMessage+="\n";
}
return ShowMessage;
}


public static String ShowDate(int yer){
String ShowYearMessage="";
for(int mon=1;mon<=12;mon++){
int daye[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int beginday=1,lostdat=0;
String ShowMessage="";

if (mon == 2)
if ((yer % 400 == 0) || ((yer % 4 == 0) && (yer % 100 != 0)))
daye[1] = 29;
else
daye[1] = 28;

Calendar ShowT = new GregorianCalendar();
ShowT.set(yer,mon-1,1);

ShowMessage+="\n" +"\t\t\t"+ yer + "年" + mon + "月" +"\n";
ShowMessage+="日\t一\t二\t三\t四\t五\t六\n";

if (((ShowT.get(Calendar.DAY_OF_WEEK)-1)+daye[mon-1])%7 != 0)
lostdat = 1;

for(int i = 1;i<= ((ShowT.get(Calendar.DAY_OF_WEEK)-1)+daye[mon-1])/7+lostdat ;i++)
{
for(int j = 1;j<=7;j++)
{
if(beginday <= (ShowT.get(Calendar.DAY_OF_WEEK)-1) || beginday > daye[mon-1] + (ShowT.get(Calendar.DAY_OF_WEEK)-1))
ShowMessage+="\t";
else
ShowMessage+=(beginday-(ShowT.get(Calendar.DAY_OF_WEEK)-1)) +"\t";
beginday++;
}
ShowMessage+="\n";
}
ShowYearMessage+=ShowMessage;
}
return ShowYearMessage;
}


}

本篇文章發表於2006-01-12 16:30
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
1樓
回應

Brian
檢舉此回應
那堿搕懂
不會全看不懂吧
本篇文章回覆於2006-01-12 22:10
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
作者回應

小咪
檢舉此回應
樓上大大...我看不懂的部分是下面這些部分...
Calendar ShowT = new GregorianCalendar();
ShowT.set(yer,mon-1,1);

ShowMessage+="\n"+"\t\t\t" + yer + "年" + mon + "月" + "\n";
ShowMessage+="日\t一\t二\t三\t四\t五\t六\n";

if (((ShowT.get(Calendar.DAY_OF_WEEK)-1)+daye[mon-1])%7 != 0)
lostdat = 1;

for(int i = 1;i<= ((ShowT.get(Calendar.DAY_OF_WEEK)-1)+daye[mon-1])/7+lostdat ;i++)
{
for(int j = 1;j<=7;j++)
{
if(beginday <= (ShowT.get(Calendar.DAY_OF_WEEK)-1) || beginday > daye[mon-1] + (ShowT.get(Calendar.DAY_OF_WEEK)-1))
ShowMessage+="\t";
else
ShowMessage+=(beginday-(ShowT.get(Calendar.DAY_OF_WEEK)-1)) +"\t";
beginday++;
}
ShowMessage+="\n";
}
return ShowMessage;
}


public static String ShowDate(int yer){
String ShowYearMessage="";
for(int mon=1;mon<=12;mon++){
int daye[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int beginday=1,lostdat=0;
String ShowMessage="";

if (mon == 2)
if ((yer % 400 == 0) || ((yer % 4 == 0) && (yer % 100 != 0)))
daye[1] = 29;
else
daye[1] = 28;

Calendar ShowT = new GregorianCalendar();
ShowT.set(yer,mon-1,1);

ShowMessage+="\n" +"\t\t\t"+ yer + "年" + mon + "月" +"\n";
ShowMessage+="日\t一\t二\t三\t四\t五\t六\n";

if (((ShowT.get(Calendar.DAY_OF_WEEK)-1)+daye[mon-1])%7 != 0)
lostdat = 1;

for(int i = 1;i<= ((ShowT.get(Calendar.DAY_OF_WEEK)-1)+daye[mon-1])/7+lostdat ;i++)
{
for(int j = 1;j<=7;j++)
{
if(beginday <= (ShowT.get(Calendar.DAY_OF_WEEK)-1) || beginday > daye[mon-1] + (ShowT.get(Calendar.DAY_OF_WEEK)-1))
ShowMessage+="\t";
else
ShowMessage+=(beginday-(ShowT.get(Calendar.DAY_OF_WEEK)-1)) +"\t";
beginday++;
}
ShowMessage+="\n";
}
ShowYearMessage+=ShowMessage;
}
return ShowYearMessage;
}


}
本篇文章回覆於2006-01-12 22:24
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
3樓
回應

Brian
檢舉此回應
如果你了解萬年曆的規則就應該看的懂
本篇文章回覆於2006-01-13 19:53
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
4樓
最有價值解答

hacker
檢舉此回應
public static String ShowDate(int yer){ //顯示年的日曆
String ShowYearMessage=""; //宣告年的空白字串
for(int mon=1;mon<=12;mon++){ //1月到十二月日的迴圈
int daye[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};// mon=1 int daye[1] = 31
int beginday=1,lostdat=0;
String ShowMessage="";

if (mon == 2) //在mon==2判斷是否為閏月,每四年潤一次
if ((yer % 400 == 0) || ((yer % 4 == 0) && (yer % 100 != 0)))
daye[1] = 29;
else
daye[1] = 28;

//待下次分析

Calendar ShowT = new GregorianCalendar();
ShowT.set(yer,mon-1,1);

ShowMessage+="\n" +"\t\t\t"+ yer + "年" + mon + "月" +"\n";
ShowMessage+="日\t一\t二\t三\t四\t五\t六\n";

if (((ShowT.get(Calendar.DAY_OF_WEEK)-1)+daye[mon-1])%7 != 0)
lostdat = 1;

for(int i = 1;i<= ((ShowT.get(Calendar.DAY_OF_WEEK)-1)+daye[mon-1])/7+lostdat ;i++)
{
for(int j = 1;j<=7;j++)
{
if(beginday <= (ShowT.get(Calendar.DAY_OF_WEEK)-1) || beginday > daye[mon-1] + (ShowT.get(Calendar.DAY_OF_WEEK)-1))
ShowMessage+="\t";
else
ShowMessage+=(beginday-(ShowT.get(Calendar.DAY_OF_WEEK)-1)) +"\t";
beginday++;
}
ShowMessage+="\n";
}
ShowYearMessage+=ShowMessage;
}
return ShowYearMessage;
}


}

public static String ShowDate(int yer,int mon)請檢查這段程式碼?

本篇文章回覆於2006-01-16 13:29
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
5樓
回應

Yen-Po Cheng
檢舉此回應
其實大概都是迴圈的應用
你還有哪邊需要註解的? 可能要再講清楚
本篇文章回覆於2019-11-04 14:45
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.