
Program to test whether a given point lies inside a circle or not?

Hi Friend,
Try the following code:
import java.util.*;
public class CheckPoint{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.print("Enter the radius of the circle : ");
double r = input.nextDouble();
System.out.println();
System.out.print("Enter x coordinate of the centre of circle : ");
double x1 = input.nextDouble();
System.out.print("Enter y coordinate of the centre of circle : ");
double y1 = input.nextDouble();
System.out.println();
System.out.print("Enter x coordinate of the point: ");
double x2 = input.nextDouble();
System.out.print("Enter y coordinate of the point: ");
double y2 = input.nextDouble();
double b=2;
double x=Math.pow(x2-x1,b);
double y=Math.pow(y2-y1,b);
System.out.println();
double check =Math.sqrt(x+y);
if (check < r){
System.out.println("Point lies inside the Circle");
}
else if (check == r){
System.out.println("Point lies on the Circle");
}
else{
System.out.println("Point lies outside the Circle");
}
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.