**Warning:** For negative odd numbers, the remainder will be -1 not 1. So we test for "not equal to zero" instead.

**Boolean:** The methods isEven and isOdd return booleans—true or false—based on the parity of the argument int.

**Here:** I test the isOdd method for negative odd numbers and it is correct. IsEven does not have a similar issue.

**Thus:** An isOdd method could correctly be equal to "!isEven." But this would not simplify our Java code.

**Quote:** Parity is a mathematical term that describes the property of an integer's inclusion in one of two categories: even or odd. An integer is even if it is "evenly divisible" by two and odd if it is not even.

Home

Dot Net Perls

© 2007-2020 Sam Allen. Every person is special and unique. Send bug reports to info@dotnetperls.com.