import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String before = sc.nextLine();
char[] after = before.toCharArray();
for (int i = 0; i < before.length(); i++) {
char word = (char) (before.charAt(i) - 3);
if (word < 'A') {
after[i] = (char) (word + 20);
} else {
after[i] = (char) (word);
}
}
System.out.print(after);
sc.close();
}
}
해당 문제에서 편지를 쓸 때,
'A'를 'D로', 'B'를 'E'로, 'C'를 'F'로... 이런 식으로 알파벳 문자를 3개씩 건너뛰어 적었다고 한다.
변환전 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
변환후 D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
해당 메소드를 사용하여 문제를 풀어보았다.
charAt()
String 문자열중 한 글자를 선택하여 char 형태로 변환
word
)을 리턴해줘야 한다.A,B,C
알파벳 문자를 입력했을 경우 'A'(65)보다 작기 때문에X,Y,Z
를 출력하기 위해서 (char) (before.charAt(i) - 3)
의 결과에 20을 더해 출력word
) 그대로 출력