Check if a given string is Even | Java program implementation of the approach ; Function to check if the string str is palindromic or not ; Pointers to iterate the string from both ends ; If characters are found to be distinct ; Return true if the string is palindromic ; Function to generate string from characters at odd indices ; Function to generate string from characters at even indices ; Functions to checks if string is Even - Odd Palindrome or not ; Generate odd indexed string ; Generate even indexed string ; Check for Palindrome ; Driver code
import java . util . * ; import java . io . * ; class GFG { 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 ; } return true ; } static String makeOddString ( String str ) { String odd = " " ; for ( int i = 1 ; i < str . length ( ) ; i += 2 ) { odd += str . charAt ( i ) ; } return odd ; } static String makeevenString ( String str ) { String even = " " ; for ( int i = 0 ; i < str . length ( ) ; i += 2 ) { even += str . charAt ( i ) ; } return even ; } static void checkevenOddPalindrome ( String str ) { String odd = makeOddString ( str ) ; String even = makeevenString ( str ) ; if ( isPalindrome ( odd ) && isPalindrome ( even ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { String str = " abzzab " ; checkevenOddPalindrome ( str ) ; } }