
import java.util.*;
public class BOJ2744 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str;
int i;
str = sc.nextLine();
for(i=0;i<str.length();i++){
if(str.charAt(i)>='A'&&str.charAt(i)<='Z')
System.out.print((char)(str.charAt(i)+32));
else if(str.charAt(i)>='a'&&str.charAt(i)<='z')
System.out.print((char)(str.charAt(i)-32));
else
System.out.print((char)(str.charAt(i)));
}
}
}
바로 출력해도 되니까 charAt를 이용해 한 글자씩 읽고, 대문자면 소문자로 출력, 소문자면 대문자로 출력, 아닌 경우에는 그냥 출력을 했다. 대소문자 구분은 아스키코드를 이용했다.

자바가 손에 안 익어서 머리로는 어떻게 해야하는지 아는데 코드를 직접 짜는게 어색했다. 하다보면 익숙해지겠지~
'코딩가딩가' 카테고리의 다른 글
| [JAVA]BOJ 13223 (0) | 2024.01.10 |
|---|---|
| [JAVA]BOJ 1543 (0) | 2024.01.04 |
| [JAVA]BOJ 1157 (0) | 2024.01.02 |
| [JAVA]BOJ 1919 (0) | 2024.01.01 |
| [JAVA]String (0) | 2023.12.28 |