iT邦幫忙

0

ASP.NET C# 是那裏有錯 ?

public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int year = Convert.ToInt32(txtyear.text);
string str;
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
{
str = "是閏年!";
}
else
{
str = "不是閏年!";

}
}
else
{
str = "是閏年!";
}
}
else
{
str = " 不是閏年!";
}
msg.Text = year + "年,"+str;

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

4
最佳解答

以語法而言, 是沒錯...

若要判斷潤年, 可以參考下列教學文~
http://www.dotblogs.com.tw/yc421206/archive/2008/11/16/6002.aspx

請問還有這題是那裏有錯呢 ?

是 string[] week, 不是 string week[]... @@
請看官方文件的Array教學...
http://msdn.microsoft.com/zh-tw/library/aa288453%28v=vs.71%29.aspx

4
temo
iT邦新手 1 級 ‧ 2013-09-02 13:36:26

superkevin提到:
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
{
str = "是閏年!";
}
else
{
str = "不是閏年!";

}
}
else
{
str = "是閏年!";
}
}
else ...(恕刪)

一個else 寫成是閏年了

aeolus0829 iT邦研究生 4 級 ‧ 2013-09-05 11:58:31 檢舉

if 寫那麼多層,看到眼睛都花了 @ @
建議改用 switch .. case

debug 較方便

我要發表回答

立即登入回答