列出项目
如何创建一个名为“niceLetters”的私有方法,它以任何大写/小写组合形式接受String,并且只返回大写的第一个字母和小写的所有其他字母?
e.g。
1。)niceLetters(“stEPheN”)返回“Stephen”
2。)niceLetters(“HELLO”)返回“Hello”
3.)niceLEtters(null)返回null
4.)niceLetters(“”)返回“”
答案 0 :(得分:0)
private static String niceLetters(String str) {
if (str == null) {
return null;
}
if (str.trim().length() <= 1) {
return str.trim().toUpperCase();
}
return (Character.toUpperCase(str.trim().charAt(0))+str.trim().substring(1).toLowerCase());
}