Count and Print the alphabets having ASCII value in the range [ l , r ] | Java implementation of the above approach ; Function to count the number of characters whose ascii value is in range [ l , r ] ; Initializing the count to 0 ; Increment the count if the value is less ; return the count ; Driver code
import java . util . * ; import java . lang . * ; class GFG { static int CountCharacters ( String str , int l , int r ) { int cnt = 0 ; int len = str . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( l <= str . charAt ( i ) && str . charAt ( i ) <= r ) { cnt ++ ; System . out . print ( str . charAt ( i ) + " ▁ " ) ; } } return cnt ; } public static void main ( String args [ ] ) { String str = " geeksforgeeks " ; int l = 102 , r = 111 ; System . out . print ( " Characters ▁ with ▁ ASCII ▁ values " + " in the range [l, r] are NEW_LINE"); System . out . print ( " and their count is " + CountCharacters ( str , l , r ) ) ; } }