문제 풀이

[백준] 14681번: 사분면 고르기 - JAVA (자바)

auyeol 2023. 1. 16. 16:19
728x90

 

 

문제

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

 

14681번: 사분면 고르기

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

www.acmicpc.net

 

점의 좌표인 2개의 정수를 입력받아 사분면의 위치를 출력하는 문제이다.

 

 

풀이

 

점 좌표 x, y를 선언한 다음, 논리연산자 AND(&&)를 이용해서 +,- 구분을 해주었다.

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(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");
		
		sc.close();
	}
}

 

728x90