为类做实验(不能使用 ARRAY )** 它是一个语言转换器,我必须在每个元音后面加上“ub” 我想知道如何在没有数组的情况下做到这一点 到目前为止我已经有了,但它只是在字符串中的第二个字母后面添加了“ub”
private static String toUbbi(String word ) {
String set = " ";
if (Vowel (word)){
set= word.substring(0)+ "ub"+word.substring(1) ;
set = word.substring(0,1)+ "ub"+word.substring(1);
}
return set;
}
private static boolean Vowel(String word ) {
String[] vowels ={ "a", "e", "i", "o", "u", "ue"} ;
//char x = word.charAt(0);
return (vowels.length !=-1);
}
最佳答案
String word = "test";
String[] vowels ={ "a", "e", "i", "o", "u"}
for (int i = (vowels.length - 1); i>=0; i-- ){
word = word.replaceAll(vowel[i], vowel[i].concat("ub"));
}
关于java - 将字符串添加到某些字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20137570/