To determine if a number is evenly divisible by x
, you should check if number % x == 0
, and you are effectively doing the exact opposite of that.
When writing expressions with multiple operators in them like the previous or in even more complicated cases like this
number % 2 == 0 and number % 3 == 0
To get things right you need to take into consideration the default operator precedence, which is order they will be performed in if no parentheses are present to override it. This means that without them, the expression will evaluated in this order:
((number % 2 == 0)) and ((number % 3 == 0))
which happens to be exactly what is needed in this case, so their use is not required. Folks sometimes put some of them in anyhow, just to make what's going on clearer. E.G.:
(number % 2 == 0) and (number % 3 == 0)