Question: JAVA: Write the method isPalindrome which should have the following signature: public class PalindromeTest { public static boolean isPalindrome( String s ) { boolean isPal

JAVA: Write the method isPalindrome which should have the following signature:

public class PalindromeTest {

public static boolean isPalindrome( String s ) {

boolean isPal = false; // assume that it is not

// code to determine if the string s is a palindrome

// If the default (as above) assumes the string is not a palindrome,

// the logic here should determine if it is and reassign the return

// variable isPal appropriately, or vice verse.

return( isPal );

}

}

**Encode the logic of the method:

1. Convert the string s to all lower case

2. Remove any character from the string which is neither a letter nor a digit. Hint: use replace (....) to replace any non-letter non-digit by the empty String "".

3. Check if the string s is a paindrome by checking to see if each letter is the same as the letter in its "mirror image" position; for example "Taco Cat" and "Toot!" are palindromes.

**Test your code on atleast the following palindromes:

- A man, a plan, a canal, Panama!

- Go hang a salami, I'm a lasagna hog!

- Campus Motto: Bottoms up, Mac!

- 7/1/17

- Are we not pure "No sir!" Panama's moody Noriega brags. It is garbage! Irony dooms a man; a prisoner up to new era.

**Note that the last quote may cause a problem because there are various kinds of smart quotes which are different from the simple ASCII double quotes; if all the others work and this one doesnt, dont worry about it!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!