대소문자 바꾸기

han.user();·2023년 4월 9일
0

구름

목록 보기
2/20
post-thumbnail

import java.io.*;
class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String length = br.readLine();
        int stringLength = Integer.parseInt(length);
        String input2 = br.readLine();
        if (input2.length() != stringLength) {
            System.out.println("알파벳 숫자가 일치하지 않습니다.");

        } else {

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < input2.length(); i++) {
                char c = input2.charAt(i);
                if (Character.isLowerCase(c)) {
                    sb.append(Character.toUpperCase(c));
                } else if (Character.isUpperCase(c)) {
                    sb.append(Character.toLowerCase(c));
                }
            }
            System.out.println(sb);
        }
    }
}

이렇게 조건을 많이 달 필요는 없는 문제인데, 최대한 완벽하게 하려고 길게 작성

profile
I'm still hungry.

0개의 댓글