Programming/BaekJoon

백준 14681번 사분면 고르기

helloworld: 2021. 7. 14. 15:50

조건은 다음과 같이 나눌 수 있다.

x가 양수인 경우 

 --> y가 양수이면 1사분면

 --> y가 음수이면 4사분면

x가 음수인 경우

 --> y가 양수이면 2사분면

 --> y가 음수이면 3사분면

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 if(y < 0){
        System.out.println("4");
      }
    } else if (x < 0) {
      if(y >0) {
        System.out.println("2");
      } else if(y < 0) {
        System.out.println("3");
      }
    }
  }
}