Finding the Quadrant of a Point in Java

Faizan FirdousiFaizan Firdousi
2 min read

๐—œ๐—ป ๐—๐—”๐—ฉ๐—” ๐—ณ๐—ผ๐˜‚๐—ป๐—ฑ ๐˜๐—ต๐—ถ๐˜€ ๐—ฝ๐—ฟ๐—ผ๐—ฏ๐—น๐—ฒ๐—บ ๐—ถ๐—ป๐˜๐—ฒ๐—ฟ๐—ฒ๐˜€๐˜๐—ถ๐—ป๐—ด ๐˜๐—ผ ๐—ฏ๐—ฒ ๐˜€๐—ผ๐—น๐˜ƒ๐—ฒ๐—ฑ ,so i did and learnt something-

๐—ฃ๐—ฟ๐—ผ๐—ฏ๐—น๐—ฒ๐—บ:
The task was to identify whether the coordinate given by the user ,falls in the 1st, 2nd, 3rd, or 4th quadrant. Additionally, I needed to handle edge cases where the point might lie on the x-axis or y-axis.

๐—›๐—ผ๐˜„ ๐—ถ ๐—ฑ๐—ถ๐—ฑ ๐—ถ๐˜ :
One interesting aspect of this project was managing the input. The user enters coordinates in the format x, y (e.g., 1, 2). Using the split() method in Java, I was able to ignore the comma and correctly parse the coordinates as integers, actually what id did was to store entire coordinate in an array and then separate it with comma and then store in 2 elements of the array . This approach ensures that even with spaces around the comma, the program processes the input smoothly.

๐—–๐—ผ๐—ป๐—ฑ๐—ถ๐˜๐—ถ๐—ผ๐—ป๐—ฎ๐—น ๐—Ÿ๐—ผ๐—ด๐—ถ๐—ฐ: the heart of the program lies in the if-else statements, which determine the quadrant based on the signs of x and y, and then i made all possible combinations

๐—ช๐—ต๐—ฎ๐˜ ๐—œ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ฒ๐—ฑ ๐—จ๐—ป๐—ถ๐—พ๐˜‚๐—ฒ (this is the only thing i learned unique because the if-else thing was cakewalk for me already)

Input Parsing: Handling user input effectively is crucial, especially when it involves common delimiters like commas. This approach helped me better understand how to clean and parse input data.

0
Subscribe to my newsletter

Read articles from Faizan Firdousi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Faizan Firdousi
Faizan Firdousi