https://school.programmers.co.kr/learn/courses/30/lessons/12930
class Solution {
public String solution(String s) {
String answer = "";
String text = "";
int space = 0;
for(int i = 0; i < s.length(); i++){
text = s.substring(i, i+1); // ํ ๊ธ์์ฉ ์๋ฆ
if(text.equals(" ")){ // ๊ณต๋ฐฑ ๋ฌธ์ ์์ ๋
answer += text;
space = 0; // ๋ฆฌ์
(๊ณต๋ฐฑ ๊ธฐ์ค ๋จ์ด ๋ณ๋ก ์ง/ํ ํ๋จ)
}
else{
if(space % 2 == 0){ // ์ง์ ์ธ๋ฑ์ค์ผ ๋
answer += text.toUpperCase(); // ๋๋ฌธ์๋ก ๋ฐ๊ฟ
}
else { // ํ์ ์ธ๋ฑ์ค์ผ ๋
answer += text.toLowerCase(); // ์๋ฌธ์๋ก ๋ฐ๊ฟ
}
space++;
}
}
return answer; // ๋ฐ๊พผ ๋ฌธ์์ด ๋ฆฌํด
}
}