【发布时间】:2023-03-27 17:00:01
【问题描述】:
我在写下这个函数的代码时遇到了麻烦。
替换辅音
/** Return a string that is s but with all lowercase consonants (letters of
* the English alphabet other than the vowels a, e, i, o, u) replaced with
* _, and all uppercase consonants replaced with ^.
*
* Examples: For s = "Minecraft" return "^i_e__a__".
* For s = "Alan Turing" return "A_a_ ^u_i__".
这是我到目前为止所做的:
String consonants = "bcdfghjklmnpqrstvwxyz";
for(int j = 0; j < consonants.length(); j++ ){
int start = 0;
if s.charAt(start) == consonants( I am unsure to tell it to look through the string I made)
s.charAt(start).replace(s.substring(start,1), ("_"));
if s.charAt(start) == s.substring(start,start+1).ToUpperCase(){
s.charAt(start) = "'";
}
}
}
【问题讨论】: