直角坐标系(Java)

版权声明:版权问题请加微信:17165380098 备注 版权问题 https://blog.csdn.net/qq_30277453/article/details/82830798

Problem Description

X是一个喜欢数学的小孩,现在他刚刚学了坐标系。他想知道点(X,Y)在第几象限内。输入数据保证点不在坐标轴及原点上。

Input

 多组输入。

每组输入两个整数X,Y,代表点(X,Y),中间用空格隔开。

Output

 输出一个整数代表点在第几象限内。

Sample Input

2 3
-2 -3

Sample Output

1
3

Java版:

import java.util.Scanner;
public class Main {
 
	public static void main(String[] args) {
     Scanner in = new Scanner(System.in);
     int a,b;
     while(in.hasNext()) {
    	 a = in.nextInt();
    	 b = in.nextInt();
    	 if(a>0&&b>0) {
    		 System.out.println("1");
    	 }
    	 else if(a>0&&b<0)
    		 System.out.println("4");
    	 else if(a<0&&b>0)
    		 System.out.println("2");
    	 else if(a<0&&b<0)
    		 System.out.println("3");

     }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_30277453/article/details/82830798
今日推荐