Skip to content

Instantly share code, notes, and snippets.

@Yuhtin
Created July 22, 2022 06:27
Show Gist options
  • Save Yuhtin/1b936aab093129e76735b5e662079bbf to your computer and use it in GitHub Desktop.
Save Yuhtin/1b936aab093129e76735b5e662079bbf to your computer and use it in GitHub Desktop.
Get four circle quadrant
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