Count consonants in a string ( Iterative and recursive methods ) | Iterative Java program to count total number of consonants ; Function to check for consonant ; To handle lower case ; To check is character is Consonant ; Driver code
import java . io . * ; class GFG { static boolean isConsonant ( char ch ) { ch = Character . toUpperCase ( ch ) ; return ! ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) && ch >= 65 && ch <= 90 ; } static int totalConsonants ( String str ) { int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) if ( isConsonant ( str . charAt ( i ) ) ) ++ count ; return count ; } public static void main ( String args [ ] ) { String str = " abc ▁ de " ; System . out . println ( totalConsonants ( str ) ) ; } }