Connect with one of the following accounts


Please wait while we redirect...

Views: 2889   

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


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.out.print("Enter the Length: ");
        double length = sc.nextDouble();

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


        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);



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

On By

Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News