Such programs are too simple and requires the fundamental logic for checking whether a number is odd or ever. Any number which is divisible by 2 is even else odd. In the below code snippet, you will find two operators % and /. x=4 y=2 x%y will computes to 0 which is the remainder!! x/y will compute to 2 which is the quotient. # Below is the code: class EvenOrOdd { public String compute(int x) { if (x % 2 == 0) { return x + " is even"; } else return x + " is odd"; } } public class TestEvenOrOdd { public static void main(String[] args) { EvenOrOdd ref = new EvenOrOdd(); System.out.println(ref.compute(5)); System.out.println(ref.compute(10)); } } #Output:
Errors and Exceptions are more common nowadays when you are trying to write simple or more complicated codes!! So you can look up Java Error Logs to get rid out of the errors. Moreover you can also find simple and more sophisticated programs solutions.