Java program that calculate the area and perimeter of the rectangle and length of the diagonal
###### Posted by Samath
Last Updated: February 09, 2021

Write a Java program that asks the user for the lengths of the sides of a rectangle.
Then print:

• The area and perimeter of the rectangle
• The length of the diagonal

Example:

Enter length: 12
Enter height: 54
Area: 648.00
Perimeter: 132.00
Diagonal length: 55.32

Code:

```import java.util.Scanner;

public class Main
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double r_height;
double r_length;
double area;
double perimeter;
double diagonal;

System.out.print("Enter length: ");
r_length = input.nextDouble();

System.out.print("Enter height: ");
r_height = input.nextDouble();
input.close();

area =  r_length * r_height;
perimeter = 	2 * (r_length + r_height);
diagonal = Math.sqrt(r_length * r_length + r_height * r_height);

System.out.printf("Area: %.2f\nPerimeter: %.2f\nDiagonal length: %.2f", area, perimeter, diagonal);
}
}
```
###### Java program that computes and displays the perimeter of a letter­size (8.5 × 11 inch) sheet of paper and the length of its diagonal
Samath | Feb 08, 2021
###### Rectangle Area in C++
Samath | Jan 20, 2024
###### C program to calculate the area of a rectangle
Samath | Jan 02, 2017
###### Rectangle Class in C++
Samath | Jan 17, 2024
###### Polygon, Rectangle and Triangle Class in Python
Samath | Jan 20, 2024
###### Write a function in C called RectArea() that returns an integer value equal to the area of the given rectangle
Samath | May 04, 2016