Dua Persegi

Assalamualaikum , . .
Kali ini saya akan membagikan ter dua persegi pada pemrograman java, ..
Langsing saj di coba, . .

import java.util.Scanner;

public class TwoRectangles {
   
    public static void main(String[] iriahus) {
        @SuppressWarnings("resource")
        Scanner s = new Scanner(System.in);
       
        System.out.print("Enter rectangle1's center x- and y-coordinate: ");
        double x1 = s.nextDouble();
        double y1 = s.nextDouble();
       
        System.out.print("Enter rectangle1's width and height: ");
        double w1 = s.nextDouble();
        double h1 = s.nextDouble();
       
        System.out.print("Enter rectangle2's center x- and y-coordinate: ");
        double x2 = s.nextDouble();
        double y2 = s.nextDouble();
       
        System.out.print("Enter rectangle2's width and height: ");
        double w2 = s.nextDouble();
        double h2 = s.nextDouble();
       
        double X = Math.abs(x1 - x2);
        double Y = Math.abs(y1 - y2);
       
        if (X + w2 / 2 <= w1 / 2 || Y + h2 / 2 <= h1 / 2)
            System.out.println("r2 is inside r1");
        else if (X + w2 / 2 >= w1 / 2 && X - h2 / 2 <= h1 / 2)
            System.out.println("r2 is overlapping r1");
        else
            System.out.println("r2 is outside r1");   
    }

}

Semoga bermanfaat, . .

Subscribe to receive free email updates:

0 Response to "Dua Persegi"

Post a Comment