☑️ 내가 쓴 답(오답)
✔ 체크 할 부분
// 두개의 알파벳 배열 (소문자,대문자) 만들어보기
class Solution {
public String solution(String my_string) {
String[] small = {"a","b","c","d","e","f","g","h","i","j"}; // length = 9
String[] big = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
String answer = "";
String[] a = my_string.split("");
for(int i = 0; i < my_string.length(); i++){
for(int j = 0; j < 10; j++){
if(a[i].equals(small[j])){
answer = answer + big[j];
}
if(a[i].equals(big[j])){
answer = answer + small[j];
}
}
}
return answer;
}
}
☑️ 다른 사람의 풀이(정답)
✔ 체크 할 부분
1) my_string이 String타입이지만, my_string.charAt(i)를 통하여 char(=문자 형식)으로 변환 가능
2) charAt[i]이 아니라, charAt(i) // 대괄호가 아니라 소괄호 // charAt은 메서드임.
3) Character 클래스를 사용하여 대문자 여부 isUpperCase(value) , 대문자로 변환 toUpperCase(value) 등 작업 가능
class Solution {
public String solution(String my_string) {
String answer = "";
for(int i = 0; i < my_string.length(); i++){
if(Character.isUpperCase(my_string.charAt(i))){
answer = answer + Character.toLowerCase(my_string.charAt(i));
} else {
answer = answer + Character.toUpperCase(my_string.charAt(i));
}
}
return answer;
}
}
'Coding Test' 카테고리의 다른 글
(SQL > ★ SELF JOIN Lev2) : 20일차 연도별 대장균 크기의 편차 구하기 (0) | 2025.04.25 |
---|---|
(CodingTest) : 25일차 영어가 싫어요 (0) | 2025.04.23 |
(SQL > COUNT,DISTINCT Lev2) : 19일차 중복 제거하기 (1) | 2025.04.23 |
(SQL > COUNT Lev2) : 19일차 동물 수 구하기 (0) | 2025.04.23 |
(SQL > MIN Lev2) : 19일차 최솟값 구하기 (0) | 2025.04.23 |