Showing posts with label simple program for Odd or Even finding. Print the accepted number is odd or even. Show all posts
Showing posts with label simple program for Odd or Even finding. Print the accepted number is odd or even. Show all posts

Wednesday, 2 July 2014

Odd or Even Program in Java

Odd or Even Check using Java Code

A Java program to accept a number from keyboard and check whether it is Odd or Even


//A small java program to check the accepted number is Odd or Even
import java.util.Scanner;

public class OddEven {

    public static void main(String args[])
   {
      int x;
      System.out.println("Enter an integer to check if it is odd or even ");
      Scanner in = new Scanner(System.in);
      x = in.nextInt();

      if ( x % 2 == 0 )
         System.out.println("You entered an even number.");
      else
         System.out.println("You entered an odd number.");
   }
    
}

Output:


Enter an integer to check if it is odd or even 
5
You entered an odd number.