Computer Science, asked by rajeshwarivaangadi, 7 months ago

Question 7:
Write a java program to accept the values for the co-ordinates x and y and display under which part of
the Quadrant it lies on the graph and also check if it is in the centre.
Ex: Sample Input1: x=-5 and y= 6 then output is Il- Quadrant.
Sample input2: x= -6 and y=-10 then it is III - Quadrant.​

Answers

Answered by anindyaadhikari13
1

Question:-

Write a java program to accept the value for the x and y coordinates and display under which part of quadrant it lies on the graph and also check if it's in the centre.

How to Do?

From the figure, we can determine the quadrant on which the x and y coordinates lie. Using those conditions, we will solve the question.

For first quadrant,

x>0 and y>0

For second quadrant,

x<0 and y>0

For third quadrant,

x<0 and y<0

For fourth quadrant,

x>0 and y<0

If the points are in the origin, then x=y=0

We will write these conditions and solve the program.

Code:-

Here is the code given below,

import java.util.*;

class Quadrant

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the value of x coordinates: ");

int x=sc.nextInt();

System.out.print("Enter the value of y coordinates: ");

int y=sc.nextInt();

String s="";

if(x>0 && y>0)

s="First Quadrant. ";

else if(x<0&&y>0)

s="Second Quadrant.";

else if(x<0&&y<0)

s="Third Quadrant.";

else if(x>0&&y<0)

s="Fourth Quadrant.";

else

s="Origin.";

System.out.println("("+x+","+y+") lies on "+s);

}

}

Attachments:
Similar questions