Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
Special words are those words which starts and ends with the same letter.
Examples:
EXISTENCE
COMIC
WINDOW
Palindrome words are those words which read the same from left to right and vice-versa.
Example:
MALAYALAM
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 print whether the word is a palindrome or only special word.
Answer:
import java.util.Scanner;
public class Words {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter word: ");
String word = scanner.next();
// Check if word is palindrome
String reverse = "";
for (int i = word.length() - 1; i >= 0; i--) {
reverse = reverse + word.charAt(i);
}
if (word.equals(reverse)) {
System.out.println("Palindrome");
}
// Check if word is a special word
char firstLetter = word.charAt(0);
char lastLetter = word.charAt(word.length() - 1);
if (firstLetter == lastLetter) {
System.out.println("Special word");
}
}
}
Sample output
Enter word: MALAYALAM
Palindrome
Special word
C. Sir| Created: 16-Apr-2019 | Updated: 16-Apr-2019|ICSE2016