Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) A palindrome is a word or phrase that reads the same forward and backwards. A

ID: 3729835 • Letter: 1

Question

1) A palindrome is a word or phrase that reads the same forward and backwards. A simple example of a palindrome is the word “radar”. “Toyota” is not a palindrome but the phrase “A Toyota” is a palindrome. Palindromes ignore letter case and punctuation. Write a program that calls a method called isPalindrome that returns true or false if an input phrase is or is not a palindrome. Your palindromeTester() method should call your isPalindrome method using the test cases below. After each line of input, print whether the input string is a palindrome or not. Your program should have this structure: main() palindromeTester() called from main boolean isPalindrome(String s) called from palindromeTester() You will capture the output for your program for the following 8 strings: "To be or not to be" "A Santa as NASA" "Acrobats stab orca" "Senile felines" "A man, a plan, a canal: Panama" "Madam, I’m Adama" "Doc, note: I dissent. A fast never prevents a fatness. I diet on cod" "radar" Tip: copy and paste these strings into your tester program to avoid typing them. Your test output should look like this: "To be or not to be" is NOT palindrome "A Santa as NASA" is NOT a palindrome "Acrobats stab orca" is a palindrome … Your isPalindrome method must reduce the input string to an array of just lower case alphabetic characters. That is an array of just alphabetic characters after removing spaces and punctuation. Your algorithm must determine whether the array is a palindrome using one for loop. You may use other for loops to filter the string and make your array of characters. Tip: Convert to lower case and remove the spaces and punctuation from the test string BEFORE trying to store the characters into an array (you need to be able to determine the correct size for the array). This problem is worth 30 pts. Grading rubric: Program structure/formatting: 10 pts isPalindrome(String s) deals with case, spaces and punctuation, uses a single array and for loop to perform test, and program produces correct output: 20 pts Printing in the isPalindrome() method: MINUS 5 pts You are NOT required to use a Scanner for input.

Explanation / Answer

Please find my implementation.Please let me know in case of any issue.

public class Pallindrome {

  

   public static boolean isPallindrome(String s) {

      

       s = s.toLowerCase();

      

       int i=0, j=s.length()-1;

      

       while(i < j) {

          

           char c1 = s.charAt(i);

           char c2 = s.charAt(j);

          

           if(!Character.isLetterOrDigit(c1)) // ignore punctuation

               i++;

           else if(!Character.isLetterOrDigit(c2))// ignore punctuation

               j--;

           else if(c1 != c2)

               return false;

           else {

               i++;

               j--;

           }

       }

      

       return true;//pallindrome

   }

  

   public static void main(String[] args) {

      

       System.out.println(isPallindrome("A Santa as NASA"));

   }

}