Count of words ending at the given suffix in Java | Function declared to return the count of words in the given sentence that end with the given suffix ; Variable to store count ; split function used to extract words from sentence in form of list ; using for loop with ' in ' to extract elements of list ; returning the count ; Driver Code ; printing the final cde
def endingWith ( str , suff ) : NEW_LINE INDENT c = 0 NEW_LINE wrd = str . split ( " ▁ " ) NEW_LINE for l in wrd : NEW_LINE INDENT if l . endswith ( suff ) : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT return c NEW_LINE DEDENT str = " GeeksForGeeks ▁ is ▁ a ▁ computer ▁ science ▁ portal ▁ for ▁ geeks " NEW_LINE suff = " ks " NEW_LINE print ( endingWith ( str , suff ) ) NEW_LINE