I'm trying to construct a program that counts the amount of vowels in a given string. Everything seems to run fine until I get to the while loop. It completely skips my if statement and goes straight to the incrementation of integer r. I feel that this is a syntax error; however, I can't imagine what it could be. Any thoughts?
String e [ ] = {"a", "e", "i", "o", "u",};
String a = "banana";
int r = 0;
int b = 0;
int c = 1;
int z = 0;
String q = " ";
for(int i = 0; i < a.length(); i++){
q = a.substring(b, c);
b++;
c++;
while(r < e.length - 1){
if(q.equalsIgnoreCase(e [r])){
z = z + 1;
}
r++;
}
}
System.out.println(z);
}
}
Aucun commentaire:
Enregistrer un commentaire