
program to count the number of vowels in a given array of characters

Hi Friend,
Try the following code:
import java.util.*;
class CountVowels{
public static void main(String args[]) throws Exception{
char ch[]=new char[5];
Scanner input=new Scanner(System.in);
System.out.println("Enter 5 characters:");
for(int i=0;i<ch.length;i++){
String st=input.next();
char c=st.charAt(0);
ch[i]=c;
}
int count = 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') {
count++;
}
}
System.out.println("There are" + " " + count + " " + "vowels in an array.");
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.