How to check whether a sentence is palindrome in JavaScript

1 Answer

0 votes
public class Palindrome {
    public static boolean isSentencePalindrome(String str) {
        // Change the string into lowercase and remove all non-alphanumeric characters
        str = str.toLowerCase().replaceAll("[^a-zA-Z0-9]", "");
         
        return str.equals(new StringBuilder(str).reverse().toString());
    }
     
    public static void main(String args[]) {
        System.out.println(isSentencePalindrome("Top step's pup's pet spot.") ? "yes": "no"); 
    }
}
 
  
/*
run:
    
yes
   
*/

 



answered Jul 1, 2024 by avibootz

Related questions

1 answer 119 views
1 answer 118 views
1 answer 123 views
1 answer 121 views
1 answer 125 views
1 answer 106 views
1 answer 99 views
...