question
Create a method that takes an integer ( >= 1 ) and returns "true" if the integer is
even and "false" if odd. You cannot use any conditional operators or switch statements.
ex. isEven(22) returns true
ex 2. isEven(1) returns false
ex. isEven(22) returns true
ex 2. isEven(1) returns false
Modulus operator will come in handy.
isEven(input)
String[] types = {"true", "false"};
print( types[input % 2] );
For this solution we take advantage of arrays and the modulus operator. An odd number mod 2 will result in 1, while an even number mod 2 will result in 0. Therefore accessing the correct value in the array to print out.
Thanks to subscriber Michael Carrano for pointing out a mistake!