Sunday, October 28, 2012

Java Exercise#36: Check Palindrome

A Palindrome is a string that reads the same when read forward or backward. Few examples are "Malayalam", "Dad" , "Mom".

The problem is to write a program that prompts the user to enter a string and then check whether it is a Palindrome or not. One intuitive solution to the problem is to compare the first and last characters of the string. If they are same, then compare the second and second-last and so on. This can continue until all characters are matched or until a mismatch is found

Exercise: Write a program that implements the above to check whether a String is a Palindrome


Enter a String: moon
moon is  not  a Palindrome!

Enter a String: malayalam
malayalam is  a Palindrome!


Download Code: Check Palindrome

No comments:

Post a Comment