I am replacing all vowels in a String with a char using a for loop.
public String replaceVowel(String text, char letter)
{
char ch;
for(int i = 0; i<text.length(); i++)
{
ch = text.charAt(i);
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y')
{
ch = letter;
}
text.charAt(i) = ch;
}
return text;
}
The code trips on an error on line:
text.charAt(i) = ch;
In this line I am attempting to initialize the char at the loop's location of the string. However the line produces the error:
The left-hand side of an assignment must be a variable
Any help is appreciated!