public class CreateStrangeStr {
public String solution(String s) {
String answer = "";
int current = 0;
s = s.toLowerCase();
String[] str = s.split("");
for (int i = 0; i < str.length; i++) {
if (str[i].equals(" ")) {
current = 0;
} else {
if (current % 2 == 0) {
str[i] = str[i].toUpperCase();
}
current++;
}
}
for (int i = 0; i < str.length; i++) {
answer += str[i];
}
return answer;
}
public static void main(String[] args) {
CreateStrangeStr s = new CreateStrangeStr();
System.out.println(s.solution("try hello world"));
}
}
- split("") : 한글자씩 잘라서 String 배열 생성. split(" ") : 공백(띄어쓰기)으로 잘라서 String 배열 생성.