Java Program to Calculate Volume of Cone

Hi everyone, In this post, we will learn Java Program to calculate Volume of Cone. A cone is a three-dimensional shape in geometry that narrows smoothly from a flat base (usually circular base) to a point(which forms an axis to the Centre of the base) called the apex or vertex.

In the previous tutorial, you have learned Java Program to Calculate area and volume of cuboid. Now let’s find the volume of the cone.

The mathematical formula for finding the volume of the cone is as follows.

Volume of cone(V) = ⅓ πr2h cubic units

Where,

  • π is a constant whose value is 3.1415 or 22/7.
  • r is the radius of its circular base.
  • h is the height from the vertex to the base.

Now let’s write the program.

Java Program to Calculate Volume of Cone

What we did ?

  • First of all we have imported the util package.
  • Then created a class and named it Cone.
  • 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 radius and height of the cone. Then read the value of radius and height of the cone entered by the user.
  • After that calculated the volume of the cone using the formula volume = (Math.PI * r * r * h)/3
  • Then finally displayed the value of volume of the cone on the screen.

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

Output

So this was all about Java Program to calculate volume of Cone tutorial. In the next tutorial, you will learn Java Program to calculate Surface Area and Volume of Sphere.


Related Tutorials…

Leave a Comment