2023-04-21 시저 암호
Summary
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.util.*;
class Solution {
public String solution(String s, int n) {
char[] arr = s.toCharArray();
for (int i=0; i<arr.length; i++) {
if (arr[i] == ' ') {
continue;
}
int offset = Character.isUpperCase(arr[i]) ? 'A':'a';
int move = (arr[i] - offset + n) % ('Z' - 'A' + 1);
arr[i] = (char) (offset + move);
}
return new String(arr);
}
}