Program to check a Number is Even or Odd.

Program to check a Number is Even or Odd


A number is even if it is divided by 2 leaves no remainder, Otherwise it is an odd number.

Example : 16 when divide by 2 leaves no remainder So 16 is even.
                 19 when divide by 2 leaves 1 remainder so 19 is odd.

Algorithm :-

  1. Input a number in a variable
  2. Using if statement check if the number divide by 2 leaves any remainder
  3. if there is no remainder then it is even number
  4. else odd number

Program below:-

import java.io.*;
import java.util.*;
class Number10
{
    public static void main(String args[])
    {
        Scanner in= new Scanner(System.in);
        int n;
        System.out.println("Enter No.");
        n= in.nextInt(); // input number from User
        if(n%2==0) // checking for even or odd
        {
            System.out.println("The Number is Even"); // Display message for Even Number
        }
        else
        {
            System.out.println("The Number is Odd"); // Display message for Odd Number
        }
    } // end of main method
} // end of class

Comments

Popular posts from this blog

Frequency of each digit of a number in Java

Trimorphic Number in JAVA

Tri-Automorphic Number in JAVA