Dua Lingkaran

Asslamualaikum, . .
Kali in saya akn membagikan  Menghiting dua lingkaran pada pemrograman java, . .
Silahkan dicoba, . .

import java.util.Scanner;

public class TwoCircles {
   
    public static void main(String[] iriahus) {
        @SuppressWarnings("resource")
        Scanner s = new Scanner(System.in);
       
        System.out.print("Enter circle1's center x-, y- coordinate: ");
        double x1 = s.nextDouble();
        double y1 = s.nextDouble();
       
        System.out.print("Enter circle1's radius: ");
        double circle1 = s.nextDouble();

        System.out.print("Enter circle2's center x-, y- coordinate: ");
        double x2 = s.nextDouble();
        double y2 = s.nextDouble();
       
        System.out.print("Enter circle2's radius: ");
        double circle2 = s.nextDouble();
       
        double d = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
       
       
        if (d + circle2 <= circle1)
            System.out.println("circle2 is inside circle1");
        else if (d + circle2 >= circle1 && d - circle2 <= circle1)
            System.out.println("circle2 is overlapping circle1");
        else
            System.out.println("circle2 is outside circle1");
    }

}

Subscribe to receive free email updates:

0 Response to "Dua Lingkaran"

Post a Comment