%2 is an easy way of testing if a number is odd or even.
public static boolean mod(int num) {
int result = num % 2;
return result == 0;
}
Function Call | Return Value | |||
---|---|---|---|---|
mod(9) | → | |||
mod(13) | → | |||
mod(10) | → | |||
mod(31) | → | |||
mod(8) | → |
Experiment with this code on Gitpod.io