String, Palindrome

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
  }
}

Write a Reply or Comment

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