Palindrome Program
Description
The program inputs a string and uses a method to determine whether or not it is a palindrome.For example, "Race car" and "Step on no pets!" are palindromes.
The program should remove blank spaces and punctuations from the input string.
Associated Concepts:
Method
String methods
String methods
Algorithm:
main method:
isPalindrome method definition:
Input a string
Convert the input string to uppercase letters
Remove the blank spaces and punctuations in the input string
Call isPalindrome method with input string as the argument and use a boolean variable flag to hold the returned value
If flag is true
Yes
Otherwise
No
Convert the input string to uppercase letters
Remove the blank spaces and punctuations in the input string
Call isPalindrome method with input string as the argument and use a boolean variable flag to hold the returned value
If flag is true
Yes
Otherwise
No
isPalindrome method definition:
Set i to the left most index of the input string
Set j to the right most index of the input string
while loop (as long as i is less than j):
Compare the characters at i and j
If they are equal, continue the process
Otherwise
Stop the process by returning false
In the end, if the while loop executed successfully in its entirety without returning false, we know that the input string is a palindrome. So the value of true is returned.
Set j to the right most index of the input string
while loop (as long as i is less than j):
Compare the characters at i and j
If they are equal, continue the process
Otherwise
Stop the process by returning false
In the end, if the while loop executed successfully in its entirety without returning false, we know that the input string is a palindrome. So the value of true is returned.