+ 3

Booleans

Is there a way to use a boolean to check if a number is even or odd?

28th Dec 2016, 11:02 PM
iiRosie1
iiRosie1 - avatar
3 Antworten
+ 2
You can use boolean logic and some math to determine if a number is even or odd. For example some pseudocode, If (X % 2 == 0) Then even else Odd Modulus can be used to determine this since if a number is divisible by 2 with no remainder, it is an even number (4, 6, 120). If not then it is odd.
28th Dec 2016, 11:13 PM
Greg Ortiz
Greg Ortiz - avatar
+ 1
write a method depending on the language from return type boolean then write a simple if your number % 2 equals 0 then return true else return false
28th Dec 2016, 11:14 PM
Andreas K
Andreas K - avatar
+ 1
Use an if else statement and the % sign. I'll leave it to you to figure it out. 😃
30th Dec 2016, 2:11 AM
Cherry
Cherry - avatar