군 전략가 머쓱이는 전쟁 중 적군이 다음과 같은 암호 체계를 사용한다는 것을 알아냈습니다.
문자열 cipher와 정수 code가 매개변수로 주어질 때 해독된 암호 문자열을 return하도록 solution 함수를 완성해주세요.
class Solution {
public String solution(String cipher, int code) {
String answer = "";
for(int i = code - 1; i < cipher.length(); i += code) {
answer += cipher.charAt(i);
}
return answer;
}
}
int i = code - 1 부터 시작한다.i += code : 반복문의 증감식. 각 반복에서 i를 code만큼 증가시킨다. 이것은 다음에 추출할 문자의 위치를 결정한다.