Leap year Test

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.