대문자와 소문자

han.user();·2023년 3월 31일
0

프로그래머스

목록 보기
10/87
post-thumbnail

class Solution {
    public String solution(String my_string) {

        String result = "";

        for (int i = 0; i < my_string.length(); i++) {
            char ch = my_string.charAt(i);
            if (ch >= 'a' && ch <= 'z') {
                // 소문자인 경우 대문자로 변경
                result += Character.toUpperCase(ch);
            } else if (ch >= 'A' && ch <= 'Z') {
                // 대문자인 경우 소문자로 변경
                result += Character.toLowerCase(ch);
            } else {
                // 알파벳이 아닌 경우 그대로 유지
                result += ch;
            }
        }
        return result;
    }
}
profile
I'm still hungry.

0개의 댓글