Start Coding Now
🌱 Beginner Programsbeginner1 methods

Check Even or Odd Number in Java

Program to check if a number is even or odd using if-else and modulus operator.

Last updated: 11 January 2026

Method 1: Using Modulus Operator

Check remainder when divided by 2.

import java.util.Scanner;

public class EvenOdd {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int num = reader.nextInt();

        if(num % 2 == 0)
            System.out.println(num + " is even");
        else
            System.out.println(num + " is odd");
    }
}
Output:
Enter a number: 29
29 is odd

Explanation

If a number is divisible by 2 (remainder 0), it is even. Otherwise, it is odd.

Frequently Asked Questions

Try This Program

Copy this code and run it in our free online Java compiler.

Open Java Compiler