我可以将小写字母替换为下一个字母。特殊字符和大写字母不应更改,但我不知道如何更改。
/** Return s but with each occurrence of a letter in 'a'..'y'
* replaced by the next letter and 'z' replaced by 'a'
*
* Examples: nextChar("") = ""
* nextChar("abcz") = "bcda"
* nextChar("1a$b") = "1b$c"
* nextChar("AB") = "AB"
* nextChar("love") = "mpwf" */
public static String nextLetter(String s) {
// TODO 3
String next = "";
for (char x: s.toCharArray()) {
next += Character.toString((char)(((x - 'a' + 1) % 26) + 'a'));
}
return next;
}
30秒到达战场
千巷猫影
相关分类