프로그래머스/lv0

머쓱이보다 키 큰 사람

do_it0904 2022. 12. 5. 10:10
/* 머쓱이보다 키 큰 사람
 * 반 친구들의 키가 담긴 정수 배열 array와
 * 머쓱이의 키 height가 매개변수로 주어질 때,
 * 머쓱이보다 키 큰 사람 수를 return
 *
 * array                height  result
 * [149, 180, 192, 170] 167     3
 * [180, 120, 140]      190     0
 */
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class programmer_0_47 {
    static int[] a1 = {149180192170};     static int b1 = 167;
    static int[] a2 = {180120140};          static int b2 = 190;
    public int solution(int[] array, int height) {
        int answer = 0;
        for(int i : array){
            if(i > height)  answer++;
        }
        return answer;
    }
    public static void main(String args[]){
        programmer_0_47 t = new programmer_0_47();
        System.out.println("---------------------------------------");
        System.out.println("result = " + t.solution(a1,b1));
        System.out.println("---------------------------------------");
        System.out.println("result2 = " + t.solution(a2,b2));
        System.out.println("---------------------------------------");
    }
}
cs