공부기록/프로그래머스

[프로그래머스] JadenCase 문자열 만들기

메델 2023. 9. 2. 03:20
import java.util.*;

class Solution {
    public String solution(String s) {
        String answer = "";
        StringTokenizer st = new StringTokenizer(s, " ", true);
        StringBuilder sb = new StringBuilder();
        
        while(st.hasMoreTokens()){
            String word = st.nextToken();
            
            if(word.equals(" ")){
                sb.append(" ");
            }else{
                sb.append(word.substring(0, 1).toUpperCase());
                sb.append(word.substring(1).toLowerCase());
            }
            
        }
        
        answer = sb.toString();
        
        return answer;
    }
}