Sentence Palindrome ( Palindrome after removing spaces , dots , . . etc ) | Java program to find if a sentence is palindrome ; To check sentence is palindrome or not ; Lowercase string ; Compares character until they are equal ; If there is another symbol in left of sentence ; If there is another symbol in right of sentence ; If characters are equal ; If characters are not equal then sentence is not palindrome ; Returns true if sentence is palindrome ; Driver program to test sentencePallindrome ( )
public class GFG { static boolean sentencePalindrome ( String str ) { int l = 0 ; int h = str . length ( ) - 1 ; str = str . toLowerCase ( ) ; while ( l <= h ) { char getAtl = str . charAt ( l ) ; char getAth = str . charAt ( h ) ; if ( ! ( getAtl >= ' a ' && getAtl <= ' z ' ) ) l ++ ; else if ( ! ( getAth >= ' a ' && getAth <= ' z ' ) ) h -- ; else if ( getAtl == getAth ) { l ++ ; h -- ; } else return false ; } return true ; } public static void main ( String [ ] args ) { String str = " Too ▁ hot ▁ to ▁ hoot . " ; if ( sentencePalindrome ( str ) ) System . out . println ( " Sentence ▁ is ▁ palindrome " ) ; else System . out . println ( " Sentence ▁ is ▁ not " + " ▁ " + " palindrome " ) ; } }