1). Write a java Palindrome program that use a recursive function call isPalindrome that returns a Boolean and accepts a string as a parameter. The program should be called from the command line / console and prompt the user to enter a string to check or Q to quit. If the first and last characters in the phrase are different, the phrase is not a palindrome. Its see as a base case and that returns false. If the phrase has one character, another base case that returns true. If the first and last characters in the phrase are the same, it is possible that the phrase is a palindrome. Apply recursion and determine if the string in positions (first+1) through (last -1) is a palindrome. Example – racecar Call isPalindrome(racecar) First and last characters are the same: racecar Return true && isPalindrome(aceca) First and last characters are the same: aceca Return true && true && isPalindrome(cec) First and last characters are the same: cec Return true && true && true && isPalindrome(e) Return true && true && true && true 2). Show how this algorithm works on the following strings using pseudo code: rester able was i ere i saw elba
1). Write a java Palindrome
If the first and last characters in the phrase are different, the phrase is not a palindrome. Its see as a base case and that returns false. If the phrase has one character, another base case that returns true. If the first and last characters in the phrase are the same, it is possible that the phrase is a palindrome. Apply recursion and determine if the string in positions (first+1) through (last -1) is a palindrome.
Example – racecar
- Call isPalindrome(racecar)
- First and last characters are the same: racecar
- Return true && isPalindrome(aceca)
- First and last characters are the same: aceca
- Return true && true && isPalindrome(cec)
- First and last characters are the same: cec
- Return true && true && true && isPalindrome(e)
- Return true && true && true && true
2). Show how this
- rester
- able was i ere i saw elba
Unlock instant AI solutions
Tap the button
to generate a solution