String, Palindrome

Palindrome is a word that reads the same backward or forward. This simple program show how to do it.

public class Palindrome {

  public static boolean isPalindrome(String word) {
    StringBuilder sb = new StringBuilder(word);
    String reverse = sb.reverse().toString().toLowerCase();
    return reverse.equalsIgnoreCase(word);
  }
    
  public static void main(String[] args) {
    System.out.println(Palindrome.isPalindrome("Deleveled")); //true
    System.out.println(Palindrome.isPalindrome("Alibaba"));   //false
    System.out.println(Palindrome.isPalindrome("System"));    //false
    System.out.println(Palindrome.isPalindrome("LOL"));       //true
  }
}
String, Palindrome

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.