Header Ads

Java Program to Check Even or Odd |Odd Or Even Program in Java

Java Program to Check Even or Odd Simple logic.

 or

Write a Java Program to Check Whether the number Odd Or Even.


 LOGIC

  • If number divisible by two, then it is even, otherwise, the number is odd. 
  • We use the Modulus Operator (%) to find the remainder. For an even number, it's zero when it's divided by two (it's one for an odd number). 
 
 Java Program to Check Even or Odd

Odd even program in Java

 Program :

import java.util.Scanner;class OddOrEven
{
  public static void main(String args[])
  {
    int x;
    System.out.println("Enter an integer to check if it's odd or even");
    Scanner in = new Scanner(System.in);
    x = in.nextInt();
    if (x % 2 == 0)
      System.out.println("The number is even.");
    else
      System.out.println("The number is odd.");
  }
}

 OUTPUT OF PROGRAM
 
        EVEN                                                   ODD
 Java Program to Check Even or Odd
 Java Program to Check Even or Odd 















No comments:

Theme images by Matt Vince. Powered by Blogger.