Created
July 22, 2022 06:27
-
-
Save Yuhtin/1b936aab093129e76735b5e662079bbf to your computer and use it in GitHub Desktop.
Get four circle quadrant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static HashMap<String, String> QUADRANTS = new HashMap<String, String>(){{ | |
put("1,1", "Q1"); | |
put("-1,1", "Q2"); | |
put("-1,-1", "Q3"); | |
put("1,-1", "Q4"); | |
}}; | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
System.out.println("Enter the number of x: "); | |
double x = scanner.nextDouble(); | |
System.out.println("Enter the number of y: "); | |
double y = scanner.nextDouble(); | |
int cartesianX = getCartesianIdentifier(x); | |
int cartesianY = getCartesianIdentifier(y); | |
String ordered = cartesianX + "," + cartesianY; | |
String value = QUADRANTS.getOrDefault(ordered, "Index"); | |
System.out.println(value); | |
} | |
public static int getCartesianIdentifier(double number) { | |
return number > 0 ? 1 : number < 0 ? -1 : 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment