perimeter of a rectangle equation code example
Example 1: java program to find perimeter of rectangle
Scanner sc = new Scanner(System.in);
System.out.println("Enter Width of the rectangle: ");
double width = sc.nextDouble();
System.out.println("Enter Height of the rectangle: ");
double height = sc.nextDouble();
sc.close();
// Logic for finding the perimeter of the rectangle
double perimeter = 2 * (width + height);
System.out.println("Perimeter of Rectangle: " + perimeter);
Example 2: calculate perimeter of rectangle in a class in python
class Rectangle:
def __init__(self, width, length):
self.length = length
self.width = width
def calculate_perimeter(self):
return 2 * (self.width + self.length)
Rectangle_1 = Rectangle(3, 4)
print (Rectangle_1.calculate_perimeter())