Implement the method countConsonants that returns the number of consonants in a string.
Count consonant letters in a string. Vowels are a, e, i, o, and u, in either lowercase or uppercase form.
The task is designed to test careful handling of edge cases, not only the most common input.
- Ignore digits, spaces, and punctuation.
- Count both uppercase and lowercase consonants.
- Return
0when no consonant exists.
For each character, first check whether it is alphabetic. If it is a letter and not a vowel, increase the count.