The problem
In this lesson, write a program that prompts the user to enter a point (x, y) and checks whether the point is within the circle centered at (0, 0) with radius 10. For example, (4, 5) is inside the circle and (9, 9) is outside the circle.
Enter a point with two coordinates: 4 5
Point (4.0, 5.0) is in the circle
Breaking it down
public static void main(String[] strings) {
Scanner input = new Scanner(System.in);
System.out.print("Enter X and Y coordinate: ");
double x = input.nextDouble();
double y = input.nextDouble();
input.close();
if (Math.pow(x * x + y * y, 0.5D) <= 10.0) {
System.out.println("Point (" + x + ", " + y + ") is in the circle");
} else {
System.out.println("Point (" + x + ", " + y
+ ") is not in the circle");
}
}
Output
Enter X and Y coordinate: 9 9
Point (9.0, 9.0) is not in the circle