If the characters are the same , then perform the swap operation as illustrated
if ( check . charAt ( mid ) == s . charAt ( mid ) ) { for ( i = 0 ; i < s . length ( ) ; i ++ ) { if ( check . charAt ( i ) != s . charAt ( mid ) && s . charAt ( i ) != s . charAt ( mid ) ) { char temp = s . charAt ( i ) ; s = s . substring ( 0 , i ) + s . charAt ( mid ) + s . substring ( i + 1 ) ; s = s . substring ( 0 , mid ) + temp + s . substring ( mid + 1 ) ; break ; } } } }