C#判斷閏年


Console.WriteLine("請輸入要判斷的年份");
int year = Convert.ToInt32(Console.ReadLine());
//年份能夠被400整除。(2000)
//年份能被4整除,但是不能被100整除。(2008)

//邏輯與的優先級高於邏輯或,最好關系運算式加括號便於閱讀

bool result = (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);

Console.WriteLine(result);
Console.ReadKey();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM