Java Program to Find the Perimeter of a Rectangle

Last Updated : 24 Jan, 2026

The perimeter of a rectangle represents the total distance around its boundary. It is calculated using the length and breadth of the rectangle.

Image
Rectangle

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)

Java
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.
Comment