This java tutorial focuses on how to check if an integer is odd or even in java. As we are already aware from our elementary mathematics that an even integer is a number which can evenly be divided into 2 while the odd integer are those numbers which always gives a remainder of 1. We will provide two solution; one is to use the modulo or remainder operator, the other is to solve it using mathematical expressions.

Integer Odd or Even in java : Using the remainder operator

This sample source code takes an integer input from the console and evaluate it if it’s an odd or even integer. Moreover we have provided mechanism to check if the input number is valid or not.

Sample Output :

If we enter an invalid character the following is a sample output

Integer Odd or Even in java : Using mathematical expression

This method as i call it is a long one. However this sample code enhances our skills on using the basic mathematical operator of java. Code is using the property of primitive type integer, use of if else, and then the operators % and *.

Sample Output :

Suggested Reading List