I know that simillar questions have been asked, but they all had the same problem: inside of the loop they had something like
i <= aString.lenth()
I used
i < phrase.length();
and I'm still getting the error. I also tried
i < phrase.length()-1;
Any ideas what is wrong?
Thanks.
public class WordPlay {
public boolean isVowel(char c) {
if(c=='a' || c=='A' || c=='e' || c=='E' || c=='i' || c=='I' || c=='o' || c=='O' || c=='u' || c=='U') {
return true;
}
else
{
return false;
}
}
public void testIsVowel () {
System.out.println(isVowel('F'));
}
public String replaceVowels (String phrase, char ch){
StringBuilder replaced = new StringBuilder(phrase);
for (int i = 0; i<phrase.length(); i++) {
char currChar = phrase.charAt(i);
if (isVowel(currChar)){
//the line below causes the error
replaced.setCharAt(currChar, ch);
}
}
return replaced.toString();
}
public void testReplaceVowels() {
System.out.println(replaceVowels("Hello World", '*'));
}
}