Write a program to check the location of a point (x, y) in a 2D coordinate system and display message differently: point (x, y) is on the original point; or is on the x-axle; or on the y-axle; or in one of 4 quadrants. When the point (x, y) is in a quadrant, the message should include quadrant information. For example, point (3, 5) is in quadrant I.
In Java Please
JAVA Code:
import java.util.*;
//main class
public class sas
{
public static void main(String args[])
{
//scanner class
Scanner sc = new Scanner(System.in);
System.out.println("Enter x & y coordinates: ");
//taking inputs of x & y coordinates
int x = sc.nextInt();
int y = sc.nextInt();
if(x==0 && y==0) //condition for origin
{
System.out.println("point ("+x+","+y+") is on the original point"); //print output
}
else if(x==0 && y!=0) //condition for y axis
{
System.out.println("point ("+x+","+y+") is on the y axle ");
}
else if(x!=0 && y==0) //condition for x axis
{
System.out.println("point ("+x+","+y+") is on the x axle ");
}
else if(x>0 && y>0) //condition for 1st quadrant
{
System.out.println("point ("+x+","+y+") is in quadrant 1 ");
}
else if(x<0 && y>0) //condition for 2nd quadrant
{
System.out.println("point ("+x+","+y+") is in quadrant 2 ");
}
else if(x<0 && y<0) //condition for 3rd quadrant
{
System.out.println("point ("+x+","+y+") is in quadrant 3 ");
}
else if(x>0 && y<0) //condition for 4th quadrant
{
System.out.println("point ("+x+","+y+") is in quadrant 4 ");
}
}
}
OUTPUTS:
Get Answers For Free
Most questions answered within 1 hours.