Java Program to Calculate Area and Volume of Cube

Hello everyone, welcome to my new tutorial on Java Program to calculate Area and Volume of Cube. 

In the previous tutorial, you have learned Java Program to Calculate Area of a Trapezium. In this tutorial, you will learn to find the Area and volume of a cube in Java. So let’s find it.

We can calculate the area and volume of a cube using the following formula.

Area of cube = 6a2

Where,

  • a is the side length of cube

Volume of cube = Side3

Where,

  • Side is the length of any edge of the cube.

Now let’s write the program.

Java Program to Calculate Area and Volume of Cube

What we did ?

  • First of all we have imported the util package.
  • Then created a class and named it Cube.
  • 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 side of the cube. Then read the value of side of the cube entered by the user.
  • Then calculated area of the cube using the formula area = 6 *(s*s)
  • After that calculated the volume of the cube using the formula volume = s * s * s.
  • Then finally displayed the value of the area and the volume of the cube on the screen.

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

Output:

So in this tutorial, we have learned Java Program to calculate Area and Volume of Cube. In the next tutorial, you will learn Java Program to calculate Area and Volume of Cuboid.


Related Tutorials…

Leave a Comment