In this post, we’ll look at how to create a Java programme that checks whether a number is even or odd. The whole numbers can be divided into odd and even numbers. Even numbers are divisible by two and have a remainder of zero. The last digits of even numbers are 0, 2, 4, 6, and 8. An odd number is one that can be divided by two but leaves a remainder of one. The last digits of odd numbers are 1, 3, 5, 7, and 9.

Even Numbers

An even number is one that is divisible by two and leaves 0 as the remainder. If the last digit of a given number is an even number, the number is considered even. Even numbers can be paired together. Even numbers will have endings of 0, 2, 4, 6, and 8.

When two even numbers are added together, the result is an even number. When an even number is added to an odd number, the result is an odd number. When you multiply any whole number, even or odd, by an even number, the result is an even number. In the even numbers, the digit in the place of the zero is always an even number digit.

Odd Numbers

An odd number is one that is not divisible by two and leaves one as the remainder. If the last digit of a given number is odd, the number itself is considered odd. Odd numbers cannot be paired together. The endings of odd numbers will be 1, 3, 5, 7, and 9.

When two odd numbers are added together, the result is an even number. When an odd number is added to an event number, the result is an odd number. When two odd numbers are multiplied, the result is an odd number. The digit in the place of the zero in odd numbers is always an odd number digit.

package in.yawin;

public class OddOrEven {
	public static void main(String[] args) {
		int value = 4;

		if (value % 2 == 0) {
			System.out.println(value + " is an even number.");
		} else {
			System.out.println(value + " is an odd number.");
		}
	}
}

Output

4 is an even number.

Explanation

If the given number is four, the output is four, which is an even number. Four is divisible by two. The remainder is zero. As a result, the value 4 is an even number.

If the given number is three, the output is three, which is an odd number. When you divide 3 by 2, the remainder value is 1. The number 3 is not divisible by two. As a result, the value 3 is an odd number.

Leave a Reply