Menu
Question Index
...


Write a program to check whether the given two circles are intersecting, touching or neither. The classification returned should be 'Circles are intersecting', 'Circles are internally touching', 'Circles are externally touching' and 'Circles are not intersecting'.
Note: While comparing lengths use only till four decimals.

Input (Circle, Circle) Output (String)
{1, 1, 3}, {2, 2, 3} Circles are intersecting
{4, 2, 3}, {5, 2, 4} Circles are internally touching
{-3, 0, 5}, {4, 0, 2} Circles are externally touching
{-3, 2, 3.16227}, {6, -1, 6.32455} Circles are externally touching
{3, -5, 2}, {3, -4, 1} Circles are internally touching
{-2, -5, 2.8284}, {-1, -4, 1.4142} Circles are internally touching
{-5, 5, 2.3}, {-2, 3, 1.1} Circles are not intersecting
{6, -1, 2}, {1, 4, 3} Circles are not intersecting

class AreCirclesIntersecting

{    public static void main(String s[])
    {
        Circle firstCircle = new Circle(3, 0, 3);
        Circle secondCircle = new Circle(0, 4, 2);
        System.out.println(areCirclesIntersecting(firstCircle, secondCircle));

    }


public static String areCirclesIntersecting(Circle firstCircle, Circle secondCircle) {
//Write code here to find whether the circles are touching or intersecting.
}

//If required, write the additional methods here.
}
class Circle {

double x;
double y;
double radius;

Circle(double x, double y, double radius) {
this.x = x;
this.y = y;
this.radius = radius;
}
}

Doubts

Problems

Topic: Java Multiple Methods In One Class

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App