QuestionAsk Questions?

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

View Answers

December 23, 2010 at 12:31 PM

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

Related Tutorials/Questions & Answers:

Advertisements