題目

判斷點是否在點上或線上或第幾項線

package ch5;
import java.io.*;
public class ch5_8
{
    public static void main(String args[])throws IOException
    {
        InputStreamReader in=new InputStreamReader(System.in);
        BufferedReader buf=new BufferedReader(in);
        int x,y;
        String sx,sy;
        sx=buf.readLine();
        x=Integer.parseInt(sx);
        sy=buf.readLine();
        y=Integer.parseInt(sy);
        System.out.print("座標("+x+","+y+")");
        if (x==0 & y ==0)
        {
            System.out.println("在原點");
        }
        else
        {
            if (x>=0)
            {
                if(x==0)
                {
                    System.out.println("在Y線上");
                }
            else
            {
                if ( y>=0 )
                {
                    if (y==0)
                    {
                        System.out.println("在X線上");
                    }
                    else
                    {
                        System.out.println("在第一象限");
                    }
                }
                else
                {
                    System.out.println("在第四象限");
                }
            }
        }
        else
        {
            if (y>=0)
            {
                if (y==0)
                {
                    System.out.println("在X線上");
                }
                else
                {
                    System.out.println("在第二象限");
                }
            }
                else
                {
                    System.out.println("在第三象限");
                }
            }
        }
    }
}

結果

-1
-1
座標(-1,-1)在第三象限

 

創作者介紹
創作者 驢子的生活日記 的頭像
驢子

驢子的生活日記

驢子 發表在 痞客邦 留言(0) 人氣( 200 )