본문 바로가기
Etc/백준(JAVA) 문제풀이

[백준] 14681번 Java 문제풀이

by pplucy 2021. 1. 7.

 

숫자의 위치가 어느 사분면에 위치하는지 알아내는 문제이다.

 

 

 

 

이 문제도 if 조건문의 조건식만 잘 성립시키면 되는 문제이다.

 

(x y) = 1 사분면

(x -y) = 4 사분면 

(-x y) =  2 사분면

(-x -y) = 3 사분면

 

이 내용을 그대로 조건문 안에 넣어주면 된다.

그림까지 친절하게 나온 문제라 쉽게 풀 수 있었다.

 

 

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
26
27
import java.util.*;
 
public class Main {
 
        public static void main(String[] args){
            
        Scanner sc = new Scanner(System.in);
        
        int x = sc.nextInt();
        int y = sc.nextInt();
        
        
        if(-1000 <= x && x <= 1000 && x !=0 && -1000 <= y && y <= 1000 && y != 0) {
            if(x > 0 && y > 0) {
                System.out.println("1");
            } else if(x > 0 && y < 0) {
                System.out.println("4");
            } else if (x < 0 && y > 0) {
                System.out.println("2");
            } else {
                System.out.println("3");
            }
        }
        
 
}
}
cs

댓글