Problem Solving
[백준/Java] 14681번 - 좌표 사분면 판별
Jintiago
2022. 3. 24. 04:17
−1000 ≤ x ≤ 1000; x ≠ 0
−1000 ≤ y ≤ 1000; y ≠ 0 일 때 입력된 좌표의 사분면 판별하기!
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
if ( x > 0 ) {
if ( y > 0) {
System.out.println(1);
} else { // y < 0 인 경우
System.out.println(4);
}
} else { // x < 0 인 경우
if ( y > 0 ) {
System.out.println(2);
} else {
System.out.println(3);
}
}
}
}