Count the number of consonants in an sentences



Problem to count the number of consonants in an string. Consonants is nothing but not an vowels alphabet.



Example-1:


Input    : S = "mycrazycoding"
Output   : 10   
Explain  : Consonants character are "m,y,c,r,z,y,c,d,n,g".


Example-2:


Input    : S = "helloworld"
Output   : 7  
Explain  : Consonants character are "h,l,l,w,r,l,d".   







Solution




public class Main
{
    public static void main(String [] args)
    {
        String s = "mycrazycoding";

        int count = 0;

        for (int i = 0; i<s.length(); i++) 
        {
            if(s.charAt(i)=='a'||s.charAt(i)=='e'||s.charAt(i)=='i'||s.charAt(i)=='o'||s.charAt(i)=='u'||s.charAt(i)=='A'||s.charAt(i)=='E'||s.charAt(i)=='I'||s.charAt(i)=='O'||s.charAt(i)=='U')
            {
                continue;
            }

            count++;

        }

        System.out.print(count);
    }
}
n = "mycrazycoding"

a = "aeiou"

k = 0

for i in range(len(n)):

    if(n[i] not in a):

        k += 1

print(k)



Output



10