I remember coding actionscript in Flash and using modulo (%) to determine if a number was even or odd. It returns the remainder of the number divided by 2 and if it equals anything other than 0 then the number is odd.
Yeah. The joke is that this is the obvious solution always used in practise, but the programmer is that bad that they don't know it and use some ridiculous alternative solutions instead.
public static boolean isEven(int number) {
// Handle negative numbers
if (number < 0) {
number = -number; // Convert to positive
}
// Subtract 2 until we reach 0 or 1
while (number > 1) {
number -= 2;
}
// If we reach 0, it's even; if we reach 1, it's odd
return number == 0;
}