본문 바로가기

Coding Test/프로그래머스

[프로그래머스/자바] 수 조작하기 1

class Solution {
    public int solution(int n, String control) {
        char[] array = control.toCharArray();
        for(char c : array) {
            if(c == 'w') n++;
            else if(c == 's') n--;
            else if(c == 'd') n += 10;
            else n -= 10;
        }
        return n;
    }
}