Loading...
Loading...
Loading...
On a city map drawn as a graph, the town hall is at the origin (0, 0). Read the x and y coordinates of a shop and print where it is:
Quadrant 1 (x > 0, y > 0), Quadrant 2 (x < 0, y > 0), Quadrant 3 (x < 0, y < 0), Quadrant 4 (x > 0, y < 0);On the x-axis when y is 0 but x is not;On the y-axis when x is 0 but y is not;Origin when both are 0.Example 1
Input
3 4
Output
Quadrant 1
Both positive.
Example 2
Input
-2 0
Output
On the x-axis
y is 0, so the point lies on the x-axis.
Example 3
Input
0 0
Output
Origin
The town hall itself.
Try the problem first. Open one hint at a time.
Handle the special points first: the origin, then the two axes.
When neither coordinate is zero, use a nested if: first split on the sign of x, then on the sign of y.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor