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

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