info@meritcampus.com    +91-85006-22255
...

Write a program to find the intersection rectangle of given two squares. Input represents [(top left x-coordinare, top left y-coordinate), Width, Height]

Input (Square, Square) Output (Rectangle)
`[(-7.0, 3.0), 3.0, 3.0] and [(-5.0, 4.0), 3.0, 3.0]` [(-5.0, 3.0), 1.0, 2.0]
`[(2.0, 2.0), 2.0, 2.0] and [(3.0, 1.0), 2.0, 2.0]` [(3.0, 1.0), 1.0, 1.0]
`[(-7.0, 3.0), 2.0, 2.0] and [(-6.0, 4.0), 4.0, 4.0]` [(-6.0, 3.0), 1.0, 2.0]
`[(-7.0, -2.0), 4.0, 4.0] and [(-7.0, -2.0), 4.0, 4.0]` [(-7.0, -2.0), 4.0, 4.0]
`[(0.0, -4.0), 3.0, 3.0] and [(0.0, 4.0), 3.0, 3.0]` null

``` class IntersectionOfTwoSquares {     public static void main(String s[])    {        Rectangle first = new Rectangle(-7, 3, 3, 3);        Rectangle second = new Rectangle(-5, 4, 3, 3);        System.out.println("Intersected rectangle as :" + intersectionOfTwoSquares(first, second));    }     public static Rectangle intersectionOfTwoSquares(Rectangle firstRectangle, Rectangle secondRectangle) { ```
```     } } class Rectangle { double topLeftX; double topLeftY; double width; double height; public Rectangle(double topLeftX, double topLeftY, double width, double height) { this.topLeftX = topLeftX; this.topLeftY = topLeftY; this.width = width; this.height = height; } @Override public String toString() { return "[(" + topLeftX + ", " + topLeftY + ")" + ", " + width + ", " + height + "]"; } } ```
0
Wrong
Score more than 2 points