I am currently creating a program that takes a string variable into my method, that string variable is copied into a new string variable which I have created. It then takes my new string variable and checks for any vowels in my String. It then takes the vowels and doubles them with my replaceAll() method. I am currently stuck on figuring out how to triple the non-vowels. So, for instance, the output for "easy!!" should be "eeaasssyyy!!!!!!.
I am looking for a simple way to do this -- any suggestions? I am a newbie to programming and Strings have me stumped.
public class RepeactChars
{
public static void main(String[] args)
{
System.out.println(repeatChars("easy!!"));
System.out.println(repeatChars("abc"));
System.out.println(repeatChars("apple"));
System.out.println(repeatChars("Homework"));
System.out.println(repeatChars("Spring"));
System.out.println(repeatChars("Integer"));
}
public static String repeatChars(String x)
{
String str = x;
str = str.replaceAll("a", "aa");
str = str.replaceAll("e", "ee");
str = str.replaceAll("i", "ii");
str = str.replaceAll("o", "oo");
str = str.replaceAll("u", "uu");
return str;
}
}