A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. Allowances may be made for adjustments to capital letters, punctuation, and word dividers.
In this simple exercise, we're going to be checking for palindromes.
Examples of palindromes:
noon
moon noom
14455441
The program prompts the user to enter a sentence or a word. It then calls the isPalindrome() method to check whether the word is actually a palindrome. It sets two variables, low and high to 0 and the length of the string - 1 respectively (remember that the string starts at 0; that's why you need the -1).
It compares the two characters at low and high locations. If at any point through the iteration the characters at the low and high locations do not equal each other the isPalindrome() method will return false.
In this simple exercise, we're going to be checking for palindromes.
Examples of palindromes:
noon
moon noom
14455441
The program prompts the user to enter a sentence or a word. It then calls the isPalindrome() method to check whether the word is actually a palindrome. It sets two variables, low and high to 0 and the length of the string - 1 respectively (remember that the string starts at 0; that's why you need the -1).
It compares the two characters at low and high locations. If at any point through the iteration the characters at the low and high locations do not equal each other the isPalindrome() method will return false.
Comments
Post a Comment