Write a function that checks if a given word is a palindrome. Character case should be ignored.
For example, isPalindrome("Deleveled") should return true as character case should be ignored, resulting in "deleveled", which is a palindrome since it reads the same backward and forward.
Reference answer
public class Palindrome {
public static boolean isPalindrome(String word) {
word = word.toLowerCase();
int len = (int) Math.floor(word.length()/2);
for(int i=0;i<len;i++){
if(word.charAt(i)!=word.charAt(word.length()-i-1)){
return false;
}
}
return true;
}
public static void main(String[] args) {
System.out.println(Palindrome.isPalindrome("Deleveled"));
}
}
No comments :
Post a Comment