본문 바로가기

프로그래머스/lv0

369게임

/*
 * 369게임
 * 말해야하는 숫자 order가 매개변수로 주어질 때,
 * 머쓱이가 쳐야할 박수 횟수를 return 하도록 solution 함수
 *
 * order    result
 * 3        1      
 * 29423    2
 */

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class programmer_0_26 {
    static int a1 = 333000;  
    static int a2 = 29423;
    public int solution(int order) {
        int answer = 0;
        String[] ar = Integer.toString(order).split("");
        for(String i : ar){
            if(Integer.parseInt(i)!=0 && Integer.parseInt(i)%3 == 0)  answer++;
        }
 
        return answer;
    }
    public static void main(String args[]){
        programmer_0_26 t = new programmer_0_26();
        System.out.println("---------------------------------------");
        System.out.println("result = " + t.solution(a1));
        System.out.println("---------------------------------------");
        // System.out.println("result2 = " + t.solution(a2));
        // System.out.println("---------------------------------------");
    }
}
cs

'프로그래머스 > lv0' 카테고리의 다른 글

대문자와 소문자  (0) 2022.12.05
암호 해독  (0) 2022.12.05
가까운 수  (1) 2022.12.05
삼각형의 완성조건 (1)  (0) 2022.12.05
분수의 덧셈  (1) 2022.12.05