[프로그래머스]이상한 문자 만들기

mongs_Develop·2022년 5월 4일
0

Programmers-Level1-Java

목록 보기
15/30
post-thumbnail
  • 문제 & 예시

  • 소스코드

// 이상한 문자 만들기
public class test15 {
	public static void main(String[] args) {
		Solution15 sol = new Solution15();
		String s = "try hello world";
		System.out.println(sol.solution(s));
	}
}
class Solution15 {
    public String solution(String s) {
        String answer = "";
        String[] arr = s.split("");
        int cnt = 0;
        
        for(int i=0;i<arr.length;i++) {
        	if(arr[i].equals(" ")) {
        		cnt = 1;
        	}else {
        		if(cnt % 2 == 0) {
            		arr[i] = arr[i].toUpperCase();
            	}else {
            		arr[i] = arr[i].toLowerCase();
            	}
        	}
        	++cnt;
        	answer += arr[i];
        }
        
        return answer;
    }
}
  • consol
profile
개 발 인생

0개의 댓글