I need this program to replace all r's with h's if they follow a vowel. This is just a test program, my actual assignment is to replace all the r's in the "Jaws" script with h's that follow a vowel, and do other various task to that string.
public static void main(String[] args) {
String s = "Hey, I'm from boston. harbor, fotter, slobber, murder.";
System.out.println(replace(s));
}
//this method should replace r with h if it follows a vowel.
public static String replace(String s) {
String newS = "";
String vowels ="aeiouAEIOU";
for (int i = 1; i < s.length(); i++) {
if (s.charAt(i) == 'r' && isVowel(s.charAt(i-1))) {
newS = s.replace("r", "h");
}
}
return newS;
}
//this method will check if a character is a vowel or not.
public static Boolean isVowel(char s) {
String vowels="aeiouAEIOU";
if (vowels.contains("" + s)) {
return true;
}
return false;
}
}