Recursive program to insert a star between pair of identical characters | Recursive Java program to insert * between two consecutive same characters . ; Function to insert * at desired position ; Append current character ; If we reached last character ; If next character is same , append ' * ' ; Driver code
class GFG { static String output = " " ; static void pairStar ( String input , int i ) { output = output + input . charAt ( i ) ; if ( i == input . length ( ) - 1 ) return ; if ( input . charAt ( i ) == input . charAt ( i + 1 ) ) output = output + ' * ' ; pairStar ( input , i + 1 ) ; } public static void main ( String [ ] args ) { String input = " geeks " ; pairStar ( input , 0 ) ; System . out . println ( output ) ; } }