# Intersection of Rectangles coderinme

#### Intersection of Rectangles coderinme

Overlapping or Intersection of Rectangles
Suppose we construct two different rectangles of different measurement, now we we intersect these rectangles,or overlap them, we come across a new rectangle.
The intersection method computes the intersection of two rectangles – that is, the rectangle that is formed by two overlapping rectangles: You call this method as follows: Rectangle r3 =r1.intersection(r2); Write a program that constructs two rectangle objects, prints them, and then prints their intersection.
Program:

``````import java.awt.Rectangle;
public class Q18
{
public static void main(String[] args)
{
Rectangle r1=new Rectangle(0,0,10,10);
System.out.println("Rectangle 1");
System.out.println(r1);
Rectangle r2=new Rectangle(0,2,10,25);
System.out.println("\nRectangle 2");
System.out.println(r2);
Rectangle r3=r1.intersection(r2);
System.out.println("\nRectangle 3(Intersection of 1 and 2)");
System.out.println(r3);
Rectangle r4=new Rectangle(20,20,14,18);
System.out.println("\nRectangle 4");
System.out.println(r4);
Rectangle r5=r1.intersection(r4);
System.out.println("\nRectangle 1 and 4 do not overlap");
System.out.println(r5);
}
}`````` 