๐Ÿ”„ Algorithm/BaekJoon

์ž๋ฐ”(Java) - ๋Œ€์†Œ๋ฌธ์ž ๋ณ€๊ฒฝํ•˜์—ฌ ์ถœ๋ ฅํ•˜๊ธฐ

kongmi 2023. 1. 9. 18:34
์˜๋ฌธ์ž ์†Œ๋ฌธ์ž์™€ ๋Œ€๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง„ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅ ๋ฐ›์€ ๋’ค,
๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋ณ€๊ฒฝํ•˜๊ธฐ(์ž…๋ ฅ์€ ๋ฌด์กฐ๊ฑด ์˜๋ฌธ์ž)
์ถœ๋ ฅ ์˜ˆ์‹œ ) abCdEF -> ABcDef
package ๋Œ€์†Œ๋ฌธ์ž๋ณ€๊ฒฝ0109;
import java.util.Scanner;

public class UpperLowerChange {
    public static void main(String[] args) {
        String str;
        int ascii;
        Scanner sc = new Scanner(System.in);
        System.out.print("์˜๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”. : ");
        str = sc.nextLine();
        for(int i = 0; i < str.length(); i++) {
            ascii = str.charAt(i);
            if(ascii >= 65 && ascii <= 90) System.out.print((char)(ascii + 32) + " ");
            if(ascii >= 97 && ascii <= 122) System.out.print((char)(ascii - 32) + " ");
        }
    }
}