Java Program to Check Whether Given Circle Resides in Boundary Maintained by Two Other Circles

bookmark

import java.io.*;
class Main
{
    public static void main(String [] args)
    {
        int x = 1 ;
        int y =2 ;
        double R =3 ;
        double r = 4;
        double rad = 5;
        // formula to find distance between the common center of 2 circles A,B 
        // and the co-ordinates of the new circle C
        double D =Math.sqrt((x*x) + (y*y));
        // Checking the corners of circle 
        if (D + rad <= R && D - rad >= R - r)  
            System.out.println("Circle Fits");  
        else
            System.out.println("Circle Doesn't Fit");
    }
}

 


Output:

Circle Doesn't Fit