In my code I am creating a window where a user can input a phrase. I am then setting up a for loop to read through the input and add ub before any vowel. My problem now is that if the user input is aeiou the output I want is ubaeiou and not ubaubeubiuboubu. I believe a Boolean variable would help but I am stuck on how to do this portion.
public void buttonPressed()
{
String line = input1.getText();
String finline;
finline = "";
line = line.toLowerCase();
for(int i =0; i < line.length(); i++)
{
if((line.charAt(i) == 'a') || (line.charAt(i) == 'e') || (line.charAt(i) == 'i') || (line.charAt(i) == 'o') || (line.charAt(i) == 'u'))
{
finline = finline + "ub" + line.charAt(i);
}
else
{
finline = finline + line.charAt(i);
}
}
output.setText(finline);
}
User input = aeiou
Output = ubaubeubiuboubu
Desired output = ubaeiou
Aucun commentaire:
Enregistrer un commentaire