Octahedron calc: find v – Java Program to Find Volume and Surface Area of Cube

Octahedron calc: find v: In the previous article we have discussed Java Program to Find Area of Parallelogram

In this article we will discuss about how to find the volume and surface area of Cube.

Program to Find Volume and Surface Area of Cube

Before jumping into the program directly, let’s first see how we calculate volume and surface area of cube.

Formula for Volume of Cube: side*side*side

Formula for Surface Area of Cube: 6*side*side

Where,

  • side‘ represents any length of any edge(length/breadth/height) of cube.
Example-1 : Volume of Cube

side = 5.5
Volume of Cube = side*side*side
                           = 5.5*5.5*5.5
                           = 166.375
Example-2 : Surface Area of Cube

side = 5.5
Surface Area of Cube = 6*side*side
                                   = 6*5.5*5.5
                                   = 181.5

Let’s see different ways to do it.

Practice Java programming from home without using any fancy software just by tapping on this Simple Java Programs for Beginners tutorial.

Method-1: Java Program to Find Volume and Surface Area of Cube By Using Static Value

import java.util.Scanner;

public class Main
{
 
    public static void main(String[] args) 
    {
        //variables declared
        double side, volume, surfaceArea;
        //Side length of cube is declared
        side = 5.5;
 
        // Calculating surface area of Cube 
        surfaceArea = 6 * side * side;
        System.out.println("Surface Area of Cube = "+ surfaceArea);
        // calculating Volume of Cube
        volume = side * side * side;
        System.out.println("Volume of Cube = "+ volume);
    }
}
Output:

Surface Area of Cube = 181.5
Volume of Cube = 166.375

Method-2: Java Program to Find Volume and Surface Area of Cube By Using User Input Value

import java.util.Scanner;

public class Main
{
 
    public static void main(String[] args) 
    {
        //variables declared
        double side, volume, surfaceArea;
        //Scanner class object created
        Scanner sc = new Scanner(System.in);
        // Taking side length input from user
        System.out.println("Enter length of side of cube : ");
        side = sc.nextDouble();
 
        // Calculating surface area of Cube 
        surfaceArea = 6 * side * side;
        System.out.println("Surface Area of Cube = "+ surfaceArea);
        // calculating Volume of Cube
        volume = side * side * side;
        System.out.println("Volume of Cube = "+ volume);
    }
}
Output:

Enter length of side of cube : 5.5
Surface Area of Cube = 181.5
Volume of Cube = 166.375

Provided list of Simple Java Programs is specially designed for freshers and beginners to get familiarize with the concepts of Java programming language and become pro in coding.

Related Java Programs: