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[]){
double diagonal;
float side;

double volume;
Scanner sc = new Scanner(System.in);
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 “);

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(“————————————————–“);

System.out.println(“Now let’s calculate the volume of a cube”);
System.out.println(“Enter the side of the cube “);
side=sc.nextFloat();
volume=sidesideside;
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
error: physicsTeacher.in