Home / Programs / Special words are those words which start and end with the same letter.Example: EXISTENCE, COMIC, WINDOWPalindrome words are those words which read the same from left to right and vice-versa.Example: MALYALAM, MADAM, LEVEL, ROTATOR, CIVICAll palindromes are special words but all special words are not palindromes. Write a program to accept a word. Check and display whether the word is a palindrome or only a special word or none of them.
🚀 Programming Example

Special words are those words which start and end with the same letter.
Example: EXISTENCE, COMIC, WINDOW
Palindrome words are those words which read the same from left to right and vice-versa.
Example: MALYALAM, MADAM, LEVEL, ROTATOR, CIVIC
All palindromes are special words but all special words are not palindromes.

Write a program to accept a word. Check and display whether the word is a palindrome or only a special word or none of them.

👁 217 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

📌 Information & Algorithm

Given Input:


Expected Output:


💻 Program Code

import java.util.Scanner;

public class RAnsariSpecialPalindrome
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a word: ");
        String str = in.next();
        str = str.toUpperCase();
        int len = str.length();

        if (str.charAt(0) == str.charAt(len - 1)) {
            boolean isPalin = true;
            for (int i = 1; i < len / 2; i++) {
                if (str.charAt(i) != str.charAt(len - 1 - i)) {
                    isPalin = false;
                    break;
                }
            }

            if (isPalin) {
                System.out.println("Palindrome");
            }
            else {
                System.out.println("Special");
            }
        }
        else {
            System.out.println("Neither Special nor Palindrome");
        }

    }
}
                        

🖥 Program Output

Enter a word: Man
Neither Special nor Palindrome
Press any key to continue . . .


Enter a word: MOM
Palindrome
Press any key to continue . . .


Enter a word: COMIC
Special
Press any key to continue . . .





                            
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.