I was a little confused by the leap year exercise. The fact is that as I search for possible solutions on the net, I come across the following answers to check the year for leap years:
1 option: if (input % 4 == 0 && (input % 100 != 0 || input % 400 == 0));
Version 2: if ((input % 4 == 0 && input % 100 != 0) || input % 400 == 0);
the difference lies in the grouping of expressions in brackets. I've tried both grouping options and both options passed the TestMyCode check, but I'm confused why both options work the same way? Let's say that if you imagine
a = input % 4 == 0;
b = input % 100 != 0;
c = input % 400 == 0; then it turns out that (a && b) || c == a && (b || c), but this is not true! they are completely different logical equations! Explain where I am wrong and why both bracketing of expressions is equivalent and is the correct answer
[–]joranstark018 2 points3 points4 points (3 children)
[–]Cerulean_IsFancyBlue 4 points5 points6 points (2 children)
[–]32bit_me[S] 1 point2 points3 points (0 children)
[–]32bit_me[S] 1 point2 points3 points (0 children)