ADVERTISEMENT
ADVERTISEMENT

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.

Java Basic Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.