이상한 문자 만들기

han.user();·2023년 4월 17일
0

프로그래머스

목록 보기
80/87
post-thumbnail

class Solution {
    public String solution(String s) {
        StringBuilder sb = new StringBuilder();
        int index = 0;
        for (char c : s.toCharArray()) {
            if (c == ' ') {
                sb.append(c);
                index = 0;
            } else {
                sb.append(index % 2 == 0 ? Character.toUpperCase(c) : Character.toLowerCase(c));
                index++;
            }
        }
        return sb.toString();
    }
}
profile
I'm still hungry.

0개의 댓글