logo image

Java program to find Area, Perimeter & Length of diagonal of a Rectangle



Rectangle is a parallelogram with opposite sides of equal length and with all right angles (90) Following image shows you how a Rectangle looks like

info-about-image

Following is the Java program that takes Length, Breadth as inputs and compute Area, Perimeter & Length of diagonal of a Rectangle

import java.util.Scanner;

public class AreaAndPerimeterOfRectangle {
	public static void main(String[] args) {

		// Taking inputs from user
		Scanner sc = new Scanner(System.in);

		System.out.print("Enter the Length: ");
		double length = sc.nextDouble();

		System.out.print("Enter the Breadth: ");
		double breadth = sc.nextDouble();

		sc.close();

		double area = length * breadth;
		double perimeter = 2 * (length + breadth);
		double diagonal = Math.sqrt((length * length) + (breadth * breadth));
		
		System.out.println("Area: " + area);
		System.out.println("Perimeter: " + perimeter);
		System.out.println("Length of diagonal: " + diagonal);

	}
}

Output

Enter the Length: 4
Enter the Breadth: 3
Area: 12.0
Perimeter: 14.0
Length of diagonal: 5.0