강의로 돌아가기
263523

도대체 이건 왜 케이스 하나만 맞는 코딩인거죠 ;; 이해가 안되네요 ...

작성중인 코드―Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution {
    public String solution(String s) {
        String answer = "";

        String[] split = s.split(" "); //글자 자르기
        String[] replace = new String[split.length];
        for (int i = 0; i < replace.length; i++) {
            replace[i]="";
        }

        for (int i = 0; i < split.length; i++) {
            for (int j = 0; j < split[i].length(); j++) {
                String word = split[i].substring(j, j+1);
                if(j%2==1){
                    replace[i]+=word;
                }else{
                    word = word.toUpperCase();
                    replace[i]+=word;
                }
            }
        }
        for (int i = 0; i < replace.length; i++) {
            answer+=replace[i];
            if(i!=replace.length-1){
                answer+=" ";
            }
        }        
        return answer;
    }
}
0 개의 답변
답변 쓰기
이 입력폼은 마크다운 문법을 지원합니다.