프로그래머스 암호 해독 문제

class Solution {
    public String solution(String cipher, int code) {
        int k = code -1;
        String answer = "";
        char[] arr = cipher.toCharArray();
        for(int i=k; i<cipher.length(); i+=code){
            answer += arr[i];
        }
        return answer;
    }
}

 

- 배열의 index는 0부터 시작하기 때문에 code에 -1.

- for문 초기식 조건식 증감식 사용시 유의사항

 = 초기식, 증감식을 자주 쓰는 int i=0, i++ 에 얽메어 있으면 안된다.