inblog logo
|
sxias
    Programmers_CT

    [Programmers_CT] 45. 수 조작하기

    문정준's avatar
    문정준
    Apr 09, 2025
    [Programmers_CT] 45. 수 조작하기
    Contents
    1. 문제 설명2. 입출력 예시3. 코드 작성4. 테스트 실행5. 제출 후 채점
     
    💡
    프로그래머스 코딩 테스트 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
    Contents
    1. 문제 설명2. 입출력 예시3. 코드 작성4. 테스트 실행5. 제출 후 채점

    Sxias ㆍ a32176740@gmail.com

    RSS·Powered by Inblog