public String solution(String s) {
String[] words = s.split(" ");
StringBuilder answerBuilder = new StringBuilder();
for (String word : words) {
if (word.isEmpty()) {
answerBuilder.append(" ");
} else {
String capitalized = word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase();
answerBuilder.append(capitalized).append(" ");
}
}
String answer = answerBuilder.toString();
if (s.substring(s.length() - 1, s.length()).equals(" ") )
return answer;
return answer.trim();
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/12951