내 답안
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.next();
String result = "";
for(int i=0; i<a.length(); i++){
char c = a.charAt(i);
if(Character.isUpperCase(c)){
result += Character.toLowerCase(c);
}else{
result += Character.toUpperCase(c);
}
}
System.out.print(result);
}
}
Java
복사
다른 사람 풀이법
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.next();
String answer = "";
for(Character c : a.toCharArray()){
if(Character.isUpperCase(c)){
answer += Character.toLowerCase(c);
}
else if(Character.isLowerCase(c)){
answer += Character.toUpperCase(c);
}
}
System.out.println(answer);
}
}
Java
복사
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.next();
for(int i=0; i<a.length(); i++) {
char c = a.charAt(i);
if(Character.isUpperCase(c)) {
System.out.print((char)(c+32));
}
else {
System.out.print((char)(c-32));
}
}
}
}
Java
복사