// Convert all characters to lowercase s = s.toLowerCase();
// Remove non-lowercase letters and non-digits Stringstr=newString(); for (inti=0; i < s.length(); i++) { if (s.charAt(i)>=97 && s.charAt(i)<=122) { str += s.charAt(i)+""; } elseif (s.charAt(i)>=48 && s.charAt(i)<=57) { str += s.charAt(i)+""; } }
/* Algorithm: Check if it is a palindrome Create a flag, which is set to true by default, indicating it is a palindrome If there is any non-palindrome condition in the loop, set the flag to false After the loop, if no non-palindrome condition is found, the flag remains true (default) */ booleanflag=true; for (inti=0; i < str.length()/2; i++) { if (!(str.charAt(i)+"").equals(str.charAt(str.length()-(1+i))+"")) { flag = false; } }