본문 바로가기

프로그래머스/lv0

머쓱이보다 키 큰 사람

/* 머쓱이보다 키 큰 사람
 * 반 친구들의 키가 담긴 정수 배열 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

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

짝수의 합  (0) 2022.12.05
양꼬치  (0) 2022.12.05
중복된 숫자의 개수  (0) 2022.12.05
옷가게 할인받기  (0) 2022.12.05
아이스 아메리카노  (0) 2022.12.05