Article

Program to check Number is Even or Odd in Java Program

In this article we will learn Program to check Number is Even or Odd in Java.


Write this code for Program to check Number is Even or Odd in Java Program

import java.util.Scanner;

class CheckNumberIsEvenOdd
{
  public static void main(String args[])
  {
    int number;
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter an Integer number:");

    //The input provided by user is stored in number
    number=sc.nextInt();
   
       /* If number  is divisible by 2 then it's an even number
     * else odd number*/
    if ( number% 2 == 0 )
        System.out.println("Entered number is even");
     else
        System.out.println("Entered number is odd");
  }
}
Advertisement

Output for Program to check Number is Even or Odd in Java Program

Advertisement

Leave a Reply

Your email address will not be published. Required fields are marked *