🧠 Problem Statement
Write a Java program to check whether a number is even or odd.
📥 Input
A number entered by the user, for example:7
📤 Output
A message:7 is an odd number.
💡 Simple Explanation
Let’s keep it super simple:
- If a number can be divided by 2 without any leftover, it’s called an even number (like 2, 4, 6).
- If there’s a leftover when dividing by 2, it’s called an odd number (like 1, 3, 5).
We use the % symbol (called the modulus operator) in Java to find out what’s left over after dividing.
🧾 Java Code
import java.util.Scanner;
public class EvenOddCheck {
public static void main(String[] args) {
// Step 1: Take input from the user
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = scanner.nextInt();
// Step 2: Check if number is even or odd
if (number % 2 == 0) {
System.out.println(number + " is an even number.");
} else {
System.out.println(number + " is an odd number.");
}
}
}
🔍 Step-by-Step (Very Lame Language 😉)
- We ask the user to enter a number.
- We use
%to check if it divides cleanly by 2. - If
number % 2 == 0, then the number is even. - Otherwise, it’s odd.
- We print the result.
📚 Example
👉 User enters: 12
✅ Output: 12 is an even number.
👉 User enters: 9
✅ Output: 9 is an odd number.
🎯 Tiny Challenge for You
Can you figure out whether a number is even or odd without using %?
(Hint: Use division and multiplication 😎)
📝 Stay tuned for tomorrow’s challenge!
Like, comment, or share if you’re learning Java with us daily! 💛

