public class StringMagic {
public String reverseWordsInSentence(String sentence) {
if(sentence == null){
return "INVALID";
}else if(sentence == ""){
return "";
}
String[] words = sentence.split(" ");
StringBuilder reversedSentence = new StringBuilder();
for(String word:words){
StringBuilder reversedStr = new StringBuilder(word).reverse();
reversedSentence.append(reversedStr).append(" ");
}
return reversedSentence.toString().trim();
}
}
728x90
'Java' 카테고리의 다른 글
[Java] 홀수 필터링하기 (0) | 2023.08.16 |
---|---|
[Java] Stream Intermediate Operations (0) | 2023.08.15 |
[Java] 16진수 문자열인지 판단하기 (0) | 2023.08.13 |
[Java] Anagram Checker (0) | 2023.08.13 |
[Java] String에서 char/String 개수 구하기 (0) | 2023.08.13 |