📜  求矩形周长的Java程序

📅  最后修改于: 2022-05-13 01:54:43.204000             🧑  作者: Mango

求矩形周长的Java程序

矩形是具有四个直角 (90°) 的四边形。在矩形中,对边相等。四边相等的矩形称为Square 。矩形也可以称为直角平行四边形。

长方形

在上面的矩形中, AC边相等, BD边相等。

一个长方形的周长是它四个边的总长。它可以简单地通过它的四个边来计算。

Perimeter of rectangle ABCD = A+B+C+D

由于矩形中的对边相等,因此可以计算为其一侧边的两倍与其相邻边的两倍之和。

Perimeter of rectangle ABCD = 2A + 2B = 2(A+B)

程序

Java
// Java program to find the perimeter of a Rectangle
  
import java.io.*;
  
class GFG {
    
    // Method to calculate the perimeter of the rectangle
    // with given length and breadth
    static void perimeter(int length, int breadth)
    {
        // Calculate the 'perimeter' using the formula
        int perimeter = 2 * (length + breadth);
        
        System.out.println("The perimeter of the given rectangle of length "
            + length + " and breadth " + breadth + " = "
            + perimeter);
    }
  
    // Driver method
    public static void main(String[] args)
    {
        // Initialize a variale length that stores length of
        // the given rectangle
        int length = 10;
        
        // Initialize a variale breadth that stores breadth
        // of the given rectangle
        int breadth = 20;
        
        // Call the perimeter method on these length and
        // breadth
        perimeter(length, breadth);
    }
}


输出
The perimeter of the given rectangle of length 10 and breadth 20 = 60