# Java program to calculate the surface area, volume, and space diagonal of cuboids

Given the values of height, width, and length, we have to calculate the surface area, volume, and space diagonal of cuboids.
Submitted by Nidhi, on February 27, 2022

Problem Solution:

In this program, we will read height, width, length from the user and calculate the surface area, volume, space diagonal of cuboids.

Program/Source Code:

The source code to calculate the surface area, volume, and space diagonal of cuboids is given below. The given program is compiled and executed successfully.

```// Java program to calculate the surface area,
// volume, and space diagonal of cuboids

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner SC = new Scanner(System.in);

float height = 0;
float width = 0;
float length = 0;

float volume = 0;
float area = 0;
float diagonal = 0;

System.out.printf("Enter the height: ");
height = SC.nextFloat();

System.out.printf("Enter the width: ");
width = SC.nextFloat();

System.out.printf("Enter the length: ");
length = SC.nextFloat();

diagonal = (float) Math.sqrt(width * width) + (length * length) + (height * height);
area = 2 * (width * length) + (length * height) + (height * width);
volume = width * length * height;

System.out.printf("Volume of Cuboids is		   : %f\n", volume);
System.out.printf("Surface area of Cuboids is  : %f\n", area);
System.out.printf("Space diagonal of Cuboids is: %f\n", diagonal);
}
}
```

Output:

```Enter the height: 1.5
Enter the width: 2.5
Enter the length: 5.6
Volume of Cuboids is               : 21.000000
Surface area of Cuboids is  : 40.150002
Space diagonal of Cuboids is: 36.110001
```

Explanation:

In the above program, we imported the "java.util.Scanner" package to read input from the user. And, created a public class Main. It contains a static method main().

The main() method is an entry point for the program. Here, we read height, width, length from the user using the Scanner class. Then we calculated the volume, area, diagonal of Cuboid and printed the result.

Preparation

What's New

Top Interview Coding Problems/Challenges!