Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

How to calculate Volume and Surface Area of Cube in Java ?

Program to calculate Volume and Surface Area of Cube in Java ?

package com.hubberspot.mensuration.example;

import java.util.Scanner;

public class Cube {

  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    double edge = 0;

    double volume = 0;
    double surfaceArea = 0;
 
    System.out.print("Enter the length of edge of Cube : "); 
    edge = input.nextDouble();

    volume = (edge * edge * edge);
    surfaceArea = 6 * (edge * edge);

    System.out.println("");
    System.out.println("The Volume of Cube is : " + volume);
    System.out.println("The Surface Area of Cube is : " + surfaceArea);
  }

}


Output of the program :



 
© 2021 Learn Java by Examples Template by Hubberspot