**Check even or odd in java** is program to check whether number is even or odd.

In this tutorial, we are looking new program which is to find an even or odd number.

**What is even number**

Any number which is divided by 2 and gives the remainder zero is Even number.

**What is odd number**

Any number which is divided by 2 but gives reminder 1 is an odd number.

To check whether a number is even or odd we need some basic mathematical formula.

The mathematical formula to find out whether a number is even or odd is as follows

**Result = Number % 2**

In above formula, The number is any number of which we are checking even or odd number.

If this number gives the reminder 0 then it’s even number else number is odd.

**Example**

Number = 10

Reminder = Number % 2

Reminder = 0

So, Number is even

Number = 5

Reminder = Number % 2

Reminder = 1

So, Number is odd.

## Java Program to check Even or Odd number

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.print("Enter a number: "); // nextInt() reads the next integer from the keyboard int num = reader.nextInt(); if ( num % 2 == 0 ) System.out.println("Entered number is even"); else System.out.println("Entered number is odd"); } } |

**Output :**

**Explanation**

**1. First, Here we declared variable **

num => to store integer value

**2. Then we took the input from a user**

num = reader.nextInt(); => num = 10

3. As we know modulus operator is used to return the remainder of two values as (10%3=1, 12%2=0).

4. So if you do modulus with 2 then the remainder would be ‘zero’ for Even numbers and ‘1’ for Odd numbers.

5. If we divide ‘number’ with ‘2’ using mod operator then depending upon condition the respective cout will be executed.

6. In above output, 10 % 2 = 0 so The number is even will be printed.

## Leave a Reply