OJ-1031: 判断点在第几象限、Java

题目描述

从键盘输入2个整数x、y值,表示平面上一个坐标点,判断该坐标点处于第几象限,并输出相应的结果。

输入

输入x,y值表示一个坐标点。坐标点不会处于x轴和y轴上,也不会在原点。

输出

输出对应的象限,用数字1,2,3,4分别对应四个象限。>

样例输入

1 1

样例输出

1

代码示例

import java.util.Scanner;
public class Main{
    
    
	public static void main(String[] args){
    
    
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int result;
		if (x > 0) {
    
    
			if (y > 0) {
    
    
				result = 1;
			}else{
    
    
				result = 4;
			}
		}else{
    
    
			if (y > 0) {
    
    
				result = 2;
			}else{
    
    
				result = 3;
			}
		}
		System.out.println(result);
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_43796109/article/details/109362614