Print the string after the specified character has occurred given no . of times | Java program for above implementation ; Method to print the string ; If given count is 0 print the given string and return ; Start traversing the string ; Increment occ if current char is equal to given character ; Break the loop if given character has been occurred given no . of times ; Print the string after the occurrence of given character given no . of times ; Otherwise string is empty ; Driver Method
public class GFG { static void printString ( String str , char ch , int count ) { int occ = 0 , i ; if ( count == 0 ) { System . out . println ( str ) ; return ; } for ( i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == ch ) occ ++ ; if ( occ == count ) break ; } if ( i < str . length ( ) - 1 ) System . out . println ( str . substring ( i + 1 ) ) ; else System . out . println ( " Empty ▁ string " ) ; } public static void main ( String [ ] args ) { String str = " geeks ▁ for ▁ geeks " ; printString ( str , ' e ' , 2 ) ; } }