Java

Java Program to Check Even or Odd Number – Explained with Examples

Java Program to Check Even or Odd Number – Complete Guide

By Bhau Automation • Simple Java program with explanation + interview questions

🎯 What is an Even or Odd Number?

In Java, a number is even if it is divisible by 2 (remainder = 0). A number is odd if dividing by 2 gives a remainder of 1.

💡 Tip: The modulus operator % helps us check the remainder in Java.

📌 Java Program to Check Even or Odd

import java.util.Scanner;

public class EvenOddChecker {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = sc.nextInt();

        if (num % 2 == 0) {
            System.out.println(num + " is an Even Number");
        } else {
            System.out.println(num + " is an Odd Number");
        }
    }
}
  

🧠 How It Works?

  • User enters a number
  • Java checks num % 2
  • If remainder is 0 → Even
  • Else → Odd

🔍 Output Example

Enter a number: 15
15 is an Odd Number

📘 Alternative Short Code

int num = 10;
System.out.println(num % 2 == 0 ? "Even" : "Odd");
  

💼 Real-Time Use Cases

  • ATM withdrawal validation
  • Game logic
  • Mathematical calculators
  • Automation scenarios

❓ Java Interview Questions

Q1: What is the modulus (%) operator in Java?

A: It returns the remainder after division.

Q2: Can we check even/odd without using % operator?

A: Yes, using bitwise operator (num & 1).

🎥 Watch the Full Video Tutorial

👉 Watch on YouTube (Java Even Odd Program)

🚀 Key Takeaways

  • Even numbers are divisible by 2
  • Use modulus operator for checking remainder
  • Java provides multiple ways to check even/odd
  • Interview often includes even-odd logic questions
⚡ Keep practicing Java basics—they are asked in every interview!

🚀 Created with ❤️ by Bhau Automation

Back to All Articles