write a program in java to accept the length and breath of a rectangle and find it's area, perimeter,diagonal
Answers
Answer:
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
Share via
KubeCon 2020 Virtual - Learn
KubeCon + CNC 2020 - Virtual Connect with leading technologists and innovators.
✕