Check given string is oddly palindrome or not | Java program for the above approach ; Function to check if the String str is palindromic or not ; Iterate the String str from left and right pointers ; Keep comparing characters while they are same ; If they are not same then return false ; Return true if the String is palindromic ; Function to make String using odd indices of String str ; Functions checks if characters at odd index of the String forms palindrome or not ; Make odd indexed String ; Check for Palindrome ; Driver Code ; Given String ; Function Call
class GFG { public static boolean isPalindrome ( String str ) { int l = 0 ; int h = str . length ( ) - 1 ; while ( h > l ) { if ( str . charAt ( l ) != str . charAt ( h ) ) { return false ; } l ++ ; h -- ; } return true ; } public static String makeOddString ( String str ) { String odd = " " ; for ( int i = 1 ; i < str . length ( ) ; i += 2 ) { odd += str . charAt ( i ) ; } return odd ; } public static void checkOddlyPalindrome ( String str ) { String odd = makeOddString ( str ) ; if ( isPalindrome ( odd ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { String str = " ddwfefwde " ; checkOddlyPalindrome ( str ) ; } }