[프로그래머스 Lv0.] 7의 개수(JAVA)

gayoung·2023년 2월 10일
0

알고리즘

목록 보기
21/50

1. 문제

문제 설명


2. 풀이 과정

내가 생각한 진행 과정

  • 숫자가 아닌 문자로 "7", "77", "17"을 두어 한자리씩 확인하면서 7이 있는지 찾아야 함

최종 코드

class Solution {
    public int solution(int[] array) {
        int answer = 0;

        for (int i=0; i<array.length; i++) {
            String word = Integer.toString(array[i]);

            for (int j=0; j<word.length(); j++) {
                if (word.substring(j, j+1).equals("7")) {
                    answer += 1;
                }
            }
        }
        return answer;
    }
}

알게된 점

  • 숫자(int)를 문자(String)으로 변경
  • String에서 문자 자르는 방법

0개의 댓글

관련 채용 정보