Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Currently, I have a program where it tells you if it is a palindrome but doesn't account for spaces and punctuation. I figured I could
Currently, I have a program where it tells you if it is a palindrome but doesn't account for spaces and punctuation. I figured I could call a sperate method to filter the string before passing it into the testPalindrome method. How could a separate method filter out the string beforehand? if not, what would be a better option?
A palindrome is a string that is spelled the same way forward and backward. Some examples of palindromes are "radar", able was i ere i saw elba", and (if spaces are ignored) "a man a plan a canal panama." Write a recursive method testPalindrome that returns boolean value true if the string stored in an array is a palindrome and false otherwise. The method should ignore spaces and punctuation in the string. (Hint: String method tocharArray gets a char array containing the String's characters.] public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner (System.in); String Pal; String Pal2; System.out.println("Please eneter palindrome"); Pal = input.nextLine(); palFilter(Pal); Pal2 = Pal; if( test Palindrome (Pal)== true) { System.out.println("Your word is a plaindrome"); else System.out.println("Your word is not a plaindrome"); public static boolean testPalindromeString Ball if( Pal == null) { return false; if (Pal.length()==1) return true; String fchar = Pal.substring (0,1); String lchar = Pal.substring (Pal.length()-1, Pal.length()); if(!fchar.equals(lchar)) return false; else return test Palindrome (Pal.substring(1, Pal.length()-1)); public static String palFilter(String Pal) { return
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started