Find Palindrome Within a String Using Java
This is one of the most commonly asked interview question, to find the palindrome’s within the given string
public class Palindrome { public static void main(String args[]){ String checkPalindrome = "Malayalam"; int length = checkPalindrome.length()/2; int mid = length; for(int i=0; i<=mid;i++){ if( checkPalindrome.charAt(mid-1) == checkPalindrome.charAt(mid+1)){ //String s1 = (checkPalindrome.substring(mid-i)) + (checkPalindrome.substring(mid+i)); System.out.println(checkPalindrome.subSequence(mid-i, mid+(i+1))); } } } }