I need to create a method which takes in a String and produces a new word which does not include vowels and replaces each consonant with its position in the original word. The word I am using is "program"
so I should get back "12o457"
.
Below is my code - I am getting an out of bounds when I try to use the deleteCharAt
but I can use append here fine.
public class Methods {
public String getWord(String word){
StringBuffer sb = new StringBuffer();
for(int i=0; i<word.length(); i++)
{
if(word.charAt(i) =='a' ||
word.charAt(i) == 'e' ||
word.charAt(i) == 'i')
{
sb.deleteCharAt(i);
}
else if(word.charAt(i)=='o' || word.charAt(i)=='u')
{
sb.append(word.charAt(i));
}
else{sb.append((i));}
}
return sb.toString();
}
}