First, Leap year definition
The number of non-whole hundred years, divisible by 4 for a leap year, the whole hundred years, divisible by 400 is a leap year.
For example: 1996 is a leap year; 2000 is a leap year; 1900 is not a leap year.
Second, Leap year program
1.
BOOL Isleapyear (int year)
{
Return year% 400 = = 0 | | (year% 4 = = 0 && Year% 100! = 0);
}
2.
public static bool Isleapyear (int year)
{
If (year% 400 = = 0)
return true;
if (year% 100 = = 0)
return false;
if (year% 4 = = 0)
return true;
return false;
}
Iii. Problems in existence
The user input type error may occur because we have defined an int type and enter the year. Example: "ABCD", Char type "1900", etc.
At this point, we need to make a judgment on what the user has entered.
1, can use try{}
catch{} for judgment.
2. Use if (), else{} or case to determine the content entered by the user. Different content for different operations, return different result values.
Leap year Test