class Solution {
public String solution(String my_string) {
String answer = "";
for(int i=0; i<my_string.length(); i++) {
Character A = my_string.charAt(i);
if(A == Character.toUpperCase(A)) {
answer += Character.toLowerCase(A);
} else if(A == Character.toLowerCase(A)) {
answer += Character.toUpperCase(A);
}
}
return answer;
}
}
stream이랑 for-each랑 이래저래 잘 쓴 답안이 있어 가져와 봄
import java.util.stream.Collectors;
class Solution {
public String solution(String myString) {
return myString.chars()
.mapToObj(operand -> String.valueOf((char) (Character.isLowerCase(operand) ? Character.toUpperCase(operand) : Character.toLowerCase(operand))))
.collect(Collectors.joining());
}
}
toArray()에 대하여...
'Study with me > 프로그래머스 L0 마스터하기' 카테고리의 다른 글
프로그래머스 - L0 정수부분 (0) | 2023.11.27 |
---|---|
프로그래머스 - L0 n의배수고르기 (0) | 2023.11.21 |
프로그래머스 - L0 세균증식 (0) | 2023.11.09 |
프로그래머스 - L0 숨어있는숫자의덧셈(1) (0) | 2023.11.09 |
프로그래머스 - L0 짝수는싫어요 (0) | 2023.11.08 |