Hi I'm trying to loop through an array of strings in count the number of times a vowel is in a word from the sentence.
String st = "Hello Today Is a lovely day";
String[] st1 = st.split(" ");
//for(int i = 0; i < st1.length; i++) {
// System.out.println(st1[i]);
//}
String vo = "AaEeIiOoUu";
for(int k = 0; k < st1.length; k++) {
int num = 0;
for(int h = 0; h < st1.length; h++) {
System.out.println(st1[k].charAt(h));
if(st1[k].charAt(h).equals(vo.charAt(h))) {
num++;
}
}
}
I can't figure out how to loop through each index of the array does anyone have any idea
There are a few issues and improvements that can be made to your code. I think this is what you need to do to solve the problem:
st.split(" ").for(int k = 0; k < st1.length; k++).Below is modified code that should solve your problem:
This is a pretty basic solution. I think it can be further optimized, but it should get you started. Hopefully this helps.