I have to get a text input from the user and then I have to replace every vowel a,e,i,o,u for 1,2,3,4,5 and show the amount of replacements for every vowel and then also the changed text. The problem is the text at the end looks nicely replaced but the amount of replacements show up as 1.
(I tried doing it below counting the 1,2,3,4 and 5s in "myText" and it works perfect but it also counts if the user inputs a number so that is a problem)
Heres the first part:
public static void replaceAndCount(String myText, int[] vowels) {
for (int i = 0; i < myText.length(); i++) {
switch (myText.charAt(i)) {
case 'a':
vowels[0]++;
myText = myText.replace('a', '1');
case 'e':
vowels[1]++;
myText = myText.replace('e', '2');
case 'i':
vowels[2]++;
myText = myText.replace('i', '3');
case 'o':
vowels[3]++;
myText = myText.replace('o', '4');
case 'u':
vowels[4]++;
myText = myText.replace('u', '5');
}
}
}