Write a Program to count the number vowels in a string

public class CountVowels{
     public static void main(String []args){
        String name ="Program TEST";
        char ch[]= name.toCharArray();
        int vowelCount = 0;
        for(int i = 0 ; i< ch.length ; i++)
        {
            if ((ch[i] == 'a' || ch[i] == 'e' || ch[i] == 'i' || ch[i] == 'o' || ch[i] == 'u') || (ch[i] == 'A' || ch[i] == 'E' || ch[i] == 'I' || ch[i] == 'O' || ch[i] == 'U'))
            vowelCount++;
        }
        System.out.println("Total number of vowels in the String is " + vowelCount);
        
     }
}

Output: –

Total number of vowels in the String is 3

Leave a Reply

Your email address will not be published. Required fields are marked *