Q:

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

belongs to collection: Java Basic Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this program, we will read heightwidthlength 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 heightwidthlength from the user using the Scanner class. Then we calculated the volume, area, diagonal of Cuboid and printed the result.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to calculate the surface area and vol... >>
<< Java program to find the Surface Area and volume o...