[Programmers_CT] 45. 수 조작하기

문정준's avatar
Apr 09, 2025
[Programmers_CT] 45. 수 조작하기
 
💡
프로그래머스 코딩 테스트 43. 수 조작하기

1. 문제 설명

notion image
 

제한 사항

notion image

2. 입출력 예시

notion image

3. 코드 작성

class Solution { public int solution(int n, String control) { int answer = 0; for(int i=0;i<control.length();i++) { String con = control.charAt(i) + ""; System.out.print(con); if(con.equals("w")) n += 1; else if(con.equals("s")) n -= 1; else if(con.equals("d")) n += 10; else if(con.equals("a")) n -= 10; } return n; } }
✏️

문자열 검사 : String.charAt(i)

  • 문자열의 각 글자를 확인해서, 글자에 따라 n 값을 계산 후 반환
    • String con = control.charAt(i) + "";

4. 테스트 실행

notion image

5. 제출 후 채점

notion image
Share article

sxias