High School Physics + more

Write a Java program to find the area, perimeter, and diagonal of a rectangle.

Here is a Java program that finds the area, perimeter, and diagonal of a rectangle. Also, this program finds the volume of a cube.

Java program – code

import java.util.Scanner;
public class RectangleCubeMeasurement

public static void main(String args[]){
float length,breadth,area,perimeter;
double diagonal;
float side;

double volume;
Scanner sc = new Scanner(;
System.out.println(“Calculation of Area, perimeter and diagonal of a rectangle”);
System.out.println(“Enter the length of the Rectangle “);
length = sc.nextFloat();

System.out.println(“Enter the breadth of the Rectangle “);
breadth = sc.nextFloat();
area=lengthbreadth; perimeter=2(length+breadth);
diagonal= Math.sqrt(lengthlength + breadthbreadth);

System.out.println(“Calculated Area, perimeter and diagonal of the given rectangle”);
System.out.println(“Area: “+ area);

System.out.println(“Perimeter: “+ perimeter);
System.out.println(“Diagonal: “+ diagonal);

System.out.println(“Now let’s calculate the volume of a cube”);
System.out.println(“Enter the side of the cube “);
System.out.println(“Calculated volume of the cube is: “+volume);

See also  Java program - how to use the Scanner class to capture user input
Scroll to top