-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_12930.java
More file actions
30 lines (29 loc) · 870 Bytes
/
_12930.java
File metadata and controls
30 lines (29 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.*;
class Solution {
public String solution(String s) {
StringBuilder sb = new StringBuilder();
int i=0;
while(i<s.length()){
// 단어가 나올 때까지 탐색
for(; i<s.length(); i++){
if(s.charAt(i)==' ') sb.append(' ');
else break;
}
// 단어 입력
int wordIndex=0;
for(; i<s.length(); i++){
char c = s.charAt(i);
if(c==' ') break;
else if(wordIndex%2==0){
if(c>='a' && c<='z') c = (char)(c+'A'-'a');
}
else {
if(c>='A' && c<='Z') c = (char)(c-'A'+'a');
}
sb.append(c);
wordIndex++;
}
}
return sb.toString();
}
}