//try 沒增加異常數據處理 Console.WriteLine("根據輸入的信息計算當年某個月份的天數,以及當年是否是閏年或平年,\n並判斷2月份特殊月份的天數。"); Console.WriteLine("請輸入需要計算的年份:"); int year = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("請輸入需要獲取的月份"); int month = Convert.ToInt32(Console.ReadLine()); switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: Console.WriteLine("是31天"); break; case 2: if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0) //閏年的判斷條件格式 // 如果 年能被400整除 或者 年能被4整除 並且年不能被100整除。 { Console.WriteLine("是閏年,2月當月的天數有29天"); } else { Console.WriteLine("是平年,2月當月的天數有28天"); } break; default: Console.WriteLine("為30天"); break; }