We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
You are saying:
if (n remainder of 2 is 1 OR (n is LARGER THAN 6 AND N is LESS THAN 20) {
do this;
}
It suppose to be:
if (n remainder of 2 is 1 AND n is NOT 0 AND (n is LARGER THAN 6 OR N is LESS THAN 20) {
do this;
}
Because you are taking in count what happens if your number is odd, right? but what if it is on say, 5, then if you have it as OR it will say "welp, this one did accomplish but this other didn't, but since one of them accomplished then who cares? Pass it boy!" But, it you used AND its like saying: "welp, this one accomplish but this one doesn't, both MUST accompish, YOU SHALL NOT PASS!". See the difference? OR is for optional, AND is a MUST between two conditions. Hope this helps!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java If-Else
You are viewing a single comment's thread. Return to all comments →
Simple, you are using an OR logic.
You are saying: if (n remainder of 2 is 1 OR (n is LARGER THAN 6 AND N is LESS THAN 20) { do this; } It suppose to be: if (n remainder of 2 is 1 AND n is NOT 0 AND (n is LARGER THAN 6 OR N is LESS THAN 20) { do this; }
Because you are taking in count what happens if your number is odd, right? but what if it is on say, 5, then if you have it as OR it will say "welp, this one did accomplish but this other didn't, but since one of them accomplished then who cares? Pass it boy!" But, it you used AND its like saying: "welp, this one accomplish but this one doesn't, both MUST accompish, YOU SHALL NOT PASS!". See the difference? OR is for optional, AND is a MUST between two conditions. Hope this helps!