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

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

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

``` class IntersectionOfTwoRectangles {     public static void main(String s[])    {        Rectangle first = new Rectangle(2, 2, 3, 2);        Rectangle second = new Rectangle(4, 1, 3, 2);        System.out.println("Intersected rectangle as :" + intersectionOfTwoRectangles(first, second));    }     public static Rectangle intersectionOfTwoRectangles(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