Convert the string into palindrome string by changing only one character | Java program to Check if it is possible to convert the string into palindrome string by changing only one character . ; Function to check if it is possible to convert the string into palindrome ; Counting number of characters that should be changed . ; If count of changes is less than or equal to 1 ; Driver Function
import java . io . * ; class GFG { static boolean checkPalindrome ( String str ) { int n = str . length ( ) ; int count = 0 ; for ( int i = 0 ; i < n / 2 ; ++ i ) if ( str . charAt ( i ) != str . charAt ( n - i - 1 ) ) ++ count ; return ( count <= 1 ) ; } public static void main ( String [ ] args ) { String str = " abccaa " ; if ( checkPalindrome ( str ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }