The perimeter of a rectangle is the total distance around its boundary. It is calculated by adding the lengths of all four sides. Since opposite sides of a rectangle are equal, the perimeter can be calculated using only its length and breadth.
- Opposite sides of a rectangle are equal.
- The formula requires only the length and breadth.
Illustration
Input: Length = 10
Breadth = 20Output: Perimeter = 60
Formula
\text{Perimeter} = 2 \times (\text{Length} + \text{Breadth})

In the above rectangle, the sides A and C are equal, and B and D are equal. The perimeter of a rectangle is the total length of all its four sides. All four sides can simply calculate it. Perimeter of rectangle ABCD = A+B+C+D
Since the opposite sides are equal in a rectangle, it can be calculated as the sum of twice one of its sides and twice its adjacent side.
Perimeter of rectangle ABCD = 2A + 2B = 2(A+B)
class GFG {
static int calculatePerimeter(int length, int breadth) {
return 2 * (length + breadth);
}
public static void main(String[] args) {
int length = 10;
int breadth = 20;
int perimeter = calculatePerimeter(length, breadth);
System.out.println("The perimeter of the rectangle is: " + perimeter);
}
}
Output
The perimeter of the rectangle is: 60
Explanation:
- The calculatePerimeter() method computes the perimeter using the formula 2 * (length + breadth) and returns the result.
- In the main method, the length and breadth of the rectangle are initialized with values 10 and 20.
- The returned perimeter value is stored and printed, producing the output 60.