Palindrome Program
package com.effectivejava; public class Palindrome { public static boolean isPalindrome(String word) { boolean isPalindrome = false;
String reverseWord = new StringBuilder(word).reverse().toString();
if (word.equalsIgnoreCase(reverseWord)) { isPalindrome = true;
}
String newWord = "";
for (int i =word.length() -1; i>=0;i--) { newWord = newWord + word.charAt(i);
}
if (word.equalsIgnoreCase(newWord)) {
isPalindrome = true;
}
return isPalindrome;
}
public static void main(String[] args) {
System.out.println(Palindrome.isPalindrome("Deleveled"));
} }
No comments:
Post a Comment