How to Return Rectangle Perimeter in Java


In this example, we will learn how to calculate perimeter of rectangle using it’s length and width.

Source Code

package com.beginner.examples;

public class RectanglePerimeterExample {

    public static void main(String[] args){
    	
    	int a = 10;
    	int b = 5;
    	//return perimeter of a rectangle.
    	double area = 2 * (a + b);
		
		System.out.println("Perimeter of a rectangle is " + area);
    }
}

Output:

Perimeter of a rectangle is 30.0
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments