본문 바로가기
Algorithm/Beakjoon

[Java] baekjoon 14681 : 사분면 고르기 / if문

by Amy97 2021. 7. 28.
728x90

문제 


https://www.acmicpc.net/problem/14681

 

14681번: 사분면 고르기

점 (x, y)의 사분면 번호(1, 2, 3, 4 중 하나)를 출력한다.

www.acmicpc.net

해결 


Quadrant 1 (양수, 양수)

Quadrant 2 (음수, 양수)

Quadrant 3 (음수, 음수)

Quadrant 4 (양수, 음수)

구현 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
 
        int x = sc.nextInt();
        int y = sc.nextInt();
 
        if (x > 0 && y > 0) {
            System.out.println("1");
        } else if (x < 0 && y > 0) {
            System.out.println("2");
        } else if (x < 0 && y < 0) {
            System.out.println("3");
        } else {
            System.out.println("4");
        }
 
    }
}
cs

결과 


728x90

댓글