The challenge

Create a function that takes an integer as an argument and returns “Even” for even numbers or “Odd” for odd numbers.

The solution in Java code

1
2
3
4
5
public class EvenOrOdd {
    public static String even_or_odd(int number) {
        return number%2==0 ? "Even" : "Odd";
    }
}

Test cases to validate our solution

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;

public class EvenOrOddTest {
    @Test
    public void testEvenOrOdd() {
        EvenOrOdd eoo = new EvenOrOdd();
        assertEquals(eoo.even_or_odd(6), "Even");
        assertEquals(eoo.even_or_odd(7), "Odd");       
    }
}