프로그래머스LV1 - 이상한 문자 만들기

Kong-al·2022년 10월 16일
0

22.10.15 D-78

프로그래머스LV1 - 이상한 문자 만들기

[ 답안 ]

class Solution {
    public String solution(String s) {
        String answer = "";
        String[] str = s.split("");
        
        int cnt = 0;
        for(int i=0; i<str.length; i++) {
            if(str[i].equals(" ")) {
                cnt = 0;
            } else if(cnt % 2 == 0) {
                str[i] = str[i].toUpperCase();
                cnt++;
            } else if(cnt % 2 != 0) {
                str[i] = str[i].toLowerCase();
                cnt++;
            }
            answer += str[i];
        } 
        
        return answer;
    }
}
profile
웹개발 공부중!(❁´◡`❁)

0개의 댓글