Count of words ending at the given suffix in Java | C # implementation of the approach ; Function to return the count of words in the given sentence that end with the given suffix ; To store the count ; Extract words from the sentence ; For every word ; If it ends with the given suffix ; Driver code
using System ; class GFG { static int endingWith ( string str , string suff ) { int cnt = 0 ; string [ ] sep = { " ▁ " } ; string [ ] words = str . Split ( sep , StringSplitOptions . RemoveEmptyEntries ) ; for ( int i = 0 ; i < words . Length ; i ++ ) { if ( words [ i ] . EndsWith ( suff ) ) cnt ++ ; } return cnt ; } public static void Main ( string [ ] args ) { string str = " GeeksForGeeks ▁ is ▁ a ▁ computer " + " ▁ science ▁ portal ▁ for ▁ geeks " ; string suff = " ks " ; Console . Write ( endingWith ( str , suff ) ) ; } }