icse-promo

Question

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.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;

public class program6
{
	public static void main(String[] args)
	{
	    int i=0;
	    Scanner sc = new Scanner(System.in);
		System.out.print("Enter the word: ");
		String wd = sc.next(); 
		/* Check whether the  word given is palindrome or not */
		String reverse = "";
		for (i = wd.length() - 1; i >= 0; i--)
		{
			reverse = reverse + wd.charAt(i);
		}

		if(wd.equals(reverse)==true)
		{
		    System.out.println(wd+" is a Palindrome word");
		}

		// Check whether the given  word is a special word
		
		if (wd.charAt(0) == wd.charAt(wd.length() - 1))
		{
		    System.out.println(wd+" is a Special word");
		}
		
		
	}
}

				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *