π§ Problem Statement
Write a Java program to check whether a word entered by the user is a palindrome or not.
π₯ Input
A word, like:madam
π€ Output
A message like:Yes, it's a palindrome!
orNo, it's not a palindrome.
π‘ What is a Palindrome?
A palindrome is a word that reads the same backward and forward.
Some examples:
π§Ύ Java Code
import java.util.Scanner;
public class PalindromeCheck {
public static void main(String[] args) {
// Step 1: Take input from the user
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a word: ");
String input = scanner.nextLine();
// Step 2: Reverse the word
String reversed = "";
for (int i = input.length() - 1; i >= 0; i--) {
reversed += input.charAt(i);
}
// Step 3: Check if input equals reversed
if (input.equals(reversed)) {
System.out.println("Yes, it's a palindrome!");
} else {
System.out.println("No, it's not a palindrome.");
}
}
}
π Step-by-Step (Explained Super Simply)
- We ask the user to type a word.
- We reverse that word letter by letter.
- We compare the original and the reversed word.
- If both are the same β itβs a palindrome.
- If not β itβs not a palindrome.
π Example
π Input: level
β
Output: Yes, it's a palindrome!
π Input: apple
β Output: No, it's not a palindrome.
π― Try This Mini Challenge
Can you do the same thing but ignore capital letters?
(Hint: Use .toLowerCase() before checking)
π See you tomorrow with Challenge #5!
Keep coding! Even small programs like this build your confidence. πͺ

