문제
https://programmers.co.kr/learn/courses/30/lessons/12930
코딩테스트 연습 - 이상한 문자 만들기
문자열 s는 한 개 이상의 단어로 구성되어 있습니다. 각 단어는 하나 이상의 공백문자로 구분되어 있습니다. 각 단어의 짝수번째 알파벳은 대문자로, 홀수번째 알파벳은 소문자로 바꾼 문자열을
programmers.co.kr
코드
class Solution {
public String solution(String s) {
String answer = "";
StringBuilder sb = new StringBuilder();
int index = 0;
for (char ch : s.toCharArray()) {
if (ch == ' ') {
index = 0;
answer += ' ';
} else {
answer += (index % 2 == 0) ? Character.toUpperCase(ch) : Character.toLowerCase(ch);
index++;
}
}
return answer;
}
}
'프로그래머스 > LEVEL 1' 카테고리의 다른 글
[프로그래머스/LEVEL1] 자연수 뒤집어 배열로 만들기 (0) | 2022.01.17 |
---|---|
[프로그래머스/LEVEL1] 자릿수 더하기 (0) | 2022.01.17 |
[프로그래머스/LEVEL1] 완주하지 못한 선수 (0) | 2022.01.15 |
[프로그래머스/LEVEL1] 서울에서 김서방 찾기 (0) | 2022.01.15 |
[프로그래머스/LEVEL1] 문자열 다루기 기본 (0) | 2022.01.15 |