문제 & 예시
소스코드
// 이상한 문자 만들기
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;
}
}