본문으로 건너뛰기
이준석 개발 블로그
돌아가기

사분면 고르기

1분 분량이 글 고치기
목차 · 8

문제

입력

출력

예제 입력 1

12 5

예제 출력 1

1

예제 입력 2

9 -13

예제 출력 2

4

코드

import java.util.Scanner;

public class Main {
    public static int checkQuadrant(int x, int y) {
        int result = 0;
        if (x > 0 && y > 0) {
            result = 1;
        }
        if (x < 0 && y > 0) {
            result = 2;
        }
        if (x < 0 && y < 0) {
            result = 3;
        }
        if (x > 0 && y < 0) {
            result = 4;
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();

        System.out.println(checkQuadrant(x, y));

    }
}

이 글 고치기
이 글 공유하기:

이전 글
시험 성적
다음 글