Open In App

Java Program to Find the Volume and Surface Area of Cuboid

Improve
Improve
Like Article
Like
Save
Share
Report

A Cuboid is a 3-dimensional box-like figure represented in the 3-dimensional plane. A cuboid has 6 rectangle-shaped faces. Each face meets another face at 90 degrees each. Three sides of cuboid meet at the same vertex. Since it is made up of 6 rectangle faces, it has length, width and height of different dimension. Given the dimensions of the cuboid, find the Surface area and Volume of a cuboid. The formula’s to calculate the area and volume are given below.

Examples:

Input : 20 15 10
Output : Surface Area = 1300
         Volume = 3000 
  

Input : 30 5 10
Output : Surface Area = 1000
         Volume = 1500

Formulas:

Volume = length * breadth * height

Surface Area of Cuboid = 2(length * breadth + breadth * height + height * length)

Approach :

  • Given the dimensions of the cone, say length L, height H and breadth B of a cuboid.
  • Calculate Volume and Surface Area

Example 1:

Java




// Java Program to Find the Volume and Surface Area of
// Cuboids
 
import java.io.*;
 
class GFG {
    public static void main(String[] args)
    {
        // specify L,B and H
        double L = 20, B = 15, H = 10;
       
        // calculate SurfaceArea
        double SurfaceArea = 2 * (L * B + B * H + H * L);
       
        // calculate Volume
        double Volume = L * B * H;
       
        System.out.println(
            "The Surface area of cuboid is : "
            + SurfaceArea);
       
        System.out.println("The Volume of the cuboid is : "
                           + Volume);
    }
}


Output

The Surface area of cuboid is : 1300.0
The Volume of the cuboid is : 3000.0

Time Complexity: O(1) as it is doing constant operations

Space Complexity: O(1)

Example 2:

Java




import java.io.*;
 
class GFG {
    public static void main(String[] args)
    {
        // specify L,B and H
        double L = 30, B = 5, H = 10;
       
        // calculate SurfaceArea
        double SurfaceArea = 2 * (L * B + B * H + H * L);
       
        // calculate Volume
        double Volume = L * B * H;
       
        System.out.println(
            "The Surface area of cuboid is : "
            + SurfaceArea);
       
        System.out.println("The Volume of the cuboid is : "
                           + Volume);
    }
}


Output

The Surface area of cuboid is : 1000.0
The Volume of the cuboid is : 1500.0

Time Complexity: O(1) as constant operations are performed

Space Complexity: O(1) since using constant variables



Last Updated : 05 Sep, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads