Jul 1, 2024
Understanding Quadrants: Visualize the question using a coordinate system.
User Input
Scanner
to get input from the user.import java.util.Scanner;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the value of x: ");
int x = sc.nextInt();
System.out.print("Enter the value of y: ");
int y = sc.nextInt();
Conditional Logic
if-else
statements to determine and print the correct quadrant based on x and y values.if (x == 0 && y == 0) {
System.out.println("Origin");
} else if (x > 0 && y > 0) {
System.out.println("Quadrant 1");
} else if (x < 0 && y > 0) {
System.out.println("Quadrant 2");
} else if (x < 0 && y < 0) {
System.out.println("Quadrant 3");
} else if (x > 0 && y < 0) {
System.out.println("Quadrant 4");
}
Compilation and Testing
x = 8
and y = -8
, the program should output Quadrant 4
.