public class Palindrome {
public static void main(String[] args) {
String str="abcdcba";
System.out.println(isPalindrome(str));
System.out.println(str.length()/2);
}
static boolean isPalindrome(String str) {
str = str.toLowerCase();
for (int i = 0; i < str.length() / 2; i++) {
char start=str.charAt(i);
char end=str.charAt(str.length() - i - 1);
if (start != end) {
return false;
}
}
return true;
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter