사분면 고르기
문제
내 풀이
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int x,y;
x = Integer.parseInt(br.readLine());
y = Integer.parseInt(br.readLine());
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);
}
}
다른 풀이
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int X = Integer.parseInt(br.readLine());
int Y = Integer.parseInt(br.readLine());
if(X > 0) {
if(Y > 0) {
System.out.print(1);
}
else {
System.out.print(4);
}
}
else {
if(Y > 0) {
System.out.print(2);
}
else {
System.out.print(3);
}
}
}
}
출처
https://st-lab.tistory.com/60