odd even program in java

Write a Program to Check Even or Odd in java

Here in this post, we are going to write a program to print even and odd numbers in java. Basic logic goes like if a number is divisible by two then it will be even, else, it Should odd. We use the modulus operator to find the remainder of a number in our program. For an even number, the remainder will be zero when it is divided by two and will be one for an odd number.

even odd number program in java : 

import java.util.Scanner;

class CheckEvenOdd
  public static void main(String args[])
    int num;
    System.out.println("Enter an Integer number:");

    //Scanner is Used to take input from the User
    Scanner input = new Scanner(System.in);
    num = input.nextInt();

    /* If number is divisible by 2 then it is an even number
     * else odd number*/
    if ( num % 2 == 0 )
        System.out.println("Entered number is even");
        System.out.println("Entered number is odd");


output Of Java Program

Write a Program to Check Even or Odd in java 1


As you can See in the Above Output We entered 5 and it classified it as Odd Number because when 5 is divided by 2 it leaves 1 as a reminder also 5 is an Odd number

The process of Running a Java program is stated below:

  • Create the program by typing it into a text editor and saving it to a file – CheckEvenOdd.java.
  • Compile it by typing “javac CheckEvenOdd.java” in the terminal window.
  • Execute (or run) it by typing “java CheckEvenOdd” in the terminal window.

Similar Posts

Notify of
Inline Feedbacks
View all comments