Video courses for company/skill based Preparation
Purchase mock tests for company/skill building
Java program to find out the quadrant in which the given co-ordinate lie
Quadrant in which the given co-ordinate lie
There are 2 axis (say x and y axis) in a two-dimensional planes. Based on values either positive or negative, a point is decided to lie on which co-ordinate. We need simple if-else statements to write a Java program to find out the quadrant in which the given co-ordinate lie. Generally there are four quadrants.
- Quadrant-1 : both x and y are positive , (+x,+y)
- Quadrant-2 : x is negative and y is positive, (-x,+y)
- Quadrant-3 : both x and y are negative, (-x,-y)
- Quadrant-4 : x is positive and y is negative, (+x,-y)
To better understand see the below example,
- x=4 and y=5 , Quadrant 1
- x=-4 and y=5, Quadrant 2
- x=-4 and y=-5 Quadrant 3
- x=4 and y=-5 Quadrant 4
- Step 1:- Start.
- Step 2:- Take inputs for X and Y.
- Step 3:- Check if X and Y are zeroes not if yes then print Origin else check if both X and y are positive Print First quadrant.
- Step 4:- Else if check X is negative and Y is positive print Second quadrant.
- Step 5:- Else if check X and Y both are negative print Third quadrant.
- Step 6:- Else if check X is positive and Y is negative print Fourth quadrant.
- Step 7:- Else print X and Y are at origin.
- Step 8:- End.
Check below Java program to find out the quadrant in which the given co-ordinate lie using above algorithm