Java Program to Check Whether a Number is Even or Odd

A number is even or odd using java :

 

Even number is a positive natural number which is completely divisible by two, where as odd number is the reverse of the even number, means odd number is also a positive natural number which is not completely divisible by two.

If N % 2 = 0, then the number is Even, else the number is Odd.

In this article, we will create a java program to check whether the number entered by the user is even or odd.

A number is even or odd using java

Working :

Step 1 : Ask the user to enter a number.

Step 2 : Check the condition for N % 2 = 0 or not. If the condition gets true, then the number is Even number, else the number is Odd number.

Step 3 : Print the result. 

Code in Java :

//Java Program to check a number is even or odd
import java.util.Scanner;
public class even_or_odd
{
public static void main(String[] args)
{
//scanner class declaration
Scanner sc = new Scanner(System.in);
//input from the user
System.out.print("Enter a Number : ");
int numb = sc.nextInt();
//condition for even
if(numb % 2 == 0)
System.out.println("Even Number");
//condition for odd
else
System.out.println("Odd Number");
//closing scanner class(not compulsory, but good practice)
sc.close();
}
}

Output :

Enter a Number : 78

Even Number


Enter a Number : 33


Odd Number