What is a leap year?
"A year, occurring once every four years, that has 366 days including February 29 as an intercalary day."
A year is a leap year if it's divisible by 4 but not by 100, or if it's divisible by 400.
In the above example, we need to group the first 2 arguments together and separate out the third.
((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
The modulo symbol % is used to find out the remainder once an equation has been evaluated.
i.e. 4 % 2 = 0 | 5 % 2 = 1 | 6 % 2 = 0 | 7 % 5 = 2 since 5 x 1 = 5 r 2
We group the first two statements and then separate the third with the use of parentheses followed by the OR operator ||
"A year, occurring once every four years, that has 366 days including February 29 as an intercalary day."
A year is a leap year if it's divisible by 4 but not by 100, or if it's divisible by 400.
In the above example, we need to group the first 2 arguments together and separate out the third.
((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
The modulo symbol % is used to find out the remainder once an equation has been evaluated.
i.e. 4 % 2 = 0 | 5 % 2 = 1 | 6 % 2 = 0 | 7 % 5 = 2 since 5 x 1 = 5 r 2
We group the first two statements and then separate the third with the use of parentheses followed by the OR operator ||
Comments
Post a Comment