본문 바로가기

프로그래머스/lv0

각도기

/* 각도기
 * 각에서 0도 초과 90도 미만은 예각, 90도는 직각,
 * 90도 초과 180도 미만은 둔각 180도는 평각으로 분류.
 * 각 angle이 매개변수로 주어질 때
 * 예각일 때 1, 직각일 때 2, 둔각일 때 3, 평각일 때 4를 return
 *
 * angle    result
 * 70       1
 * 91       3
 * 180      4
 */
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class programmer_0_44 {
    static int a1 = 70;
    static int a2 = 91;
    static int a3 = 180;
    public int solution(int angle) {
        int answer = 0;
        if(angle > 0 && angle < 90) answer = 1;
        else if(angle == 90)   answer = 2;
        else if(angle > 90 && angle < 180 )  answer = 3;
        else if(angle == 180 )  answer = 4;
        return answer;
        // 다른사람 풀이
        // return angle == 180 ? 4 : angle < 90 ? 1 : angle == 90 ? 2 : angle > 90 ? 3 : 0;
    }
    public static void main(String args[]){
        programmer_0_44 t = new programmer_0_44();
 
        System.out.println("---------------------------------------");
        System.out.println("result = " + t.solution(a1));
        System.out.println("---------------------------------------");
        System.out.println("result2 = " + t.solution(a2));
        System.out.println("---------------------------------------");
        System.out.println("result3 = " + t.solution(a3));
        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