Java Program to Calculate Area and Volume of Cuboid

Hello everyone, in this tutorial, we will learn Java Program to calculate Area and Volume of Cuboid. Have you checked the previous tutorial, Java Program to calculate Area and Volume of Cube? If not, then now you can check it out.

Calculating the area and volume of a cuboid in Java is not difficult. It can be done in just a few lines of code. But first, we need to know the mathematical formula to find the area and volume of the cuboid. So let’s know this.

Area of cuboid = 2 (lb + bh + lh)

Where,

  • l is length of the cuboid.
  • b is breadth of the cuboid.
  • h is height of the cuboid.

Volume of cuboid =l×b×h

Where,

  • l is length of the cuboid
  • b is breadth of the cuboid
  • h is height of the cuboid.

Now let’s write the program. Here is the complete source code of this program, and explanations are given after the program.

Java Program to Calculate Area and Volume of Cuboid

What we did ?

  • First of all we have imported the util package.
  • Then created a class and named it Cuboid.
  • After that started main() method of the program.
  • Then inside main() method declared variables.
  • Then created object of the Scanner class.
  • Now asked the user to enter the length, breadth, and height of the cuboid. Then read the value of length, breadth, and height of the cuboid entered by the user.
  • Then calculated area of the cuboid using the formula area = l * b * h.
  • After that calculated volume of the cuboid using the formula volume = 2*(l*b + b*h + l*h).
  • Then finally displayed the value of area and volume of the cuboid on the screen.

Now let’s check the output of the above code.

Output

So guys, Java Program to calculate Area and Volume of Cuboid tutorial is completed. In the next tutorial, you will learn Java Program to calculate Volume of Cone.


Related Tutorials…

Leave a Comment