프로그래머스/lv0
점의 위치 구하기
do_it0904
2022. 12. 5. 09:58
/* 점의 위치 구하기
* 사분면은 한 평면을 x축과 y축을 기준으로 나눈 네 부분입니다.
* 사분면은 아래와 같이 1부터 4까지 번호를매깁니다.
* x 좌표 (x, y)를 차례대로 담은 정수 배열 dot이 매개변수로 주어집니다.
* 좌표 dot이 사분면 중 어디에 속하는지 1, 2, 3, 4 중 하나를 return
*
* dot result
* [2, 4] 1
* [-7, 9] 2
*/
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 | public class programmer_0_63 { static int[] a1 = {2, 4}; static int[] a2 = {-7, 9}; public int solution(int[] dot) { int answer = 0; if(dot[0] > 0){ if(dot[1] > 0) answer = 1; else answer = 4; } else{ if(dot[1] > 0) answer = 2; else answer = 3; } return answer; } public static void main(String args[]){ programmer_0_63 t = new programmer_0_63(); System.out.println("---------------------------------------"); System.out.println("result = " + t.solution(a1)); System.out.println("---------------------------------------"); // System.out.println("result2 = " + t.solution(a2)); // System.out.println("---------------------------------------"); } } | cs |