Q:

Java program to calculate the area of Cube

belongs to collection: Java Basic Programs

0

Java program to calculate the area of Cube

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this program, we will read the length of sides of the Cube from the user and calculate the area of Cube. Then we will print the result.

Program/Source Code:

The source code to calculate the area of Cube is given below. The given program is compiled and executed successfully.

// Java program to calculate the 
// area of Cube

import java.util.Scanner;

public class Main {
  static float calcuateAreaOfCube(float side) {
    float result = 0.0F;

    result = 6.0F * side * side;

    return result;
  }

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

    float side = 0;
    float area = 0;

    System.out.printf("Enter the length of side: ");
    side = SC.nextFloat();

    area = calcuateAreaOfCube(side);

    System.out.printf("Area of Cube is: %f\n", area);
  }
}

Output:

Enter the length of side: 10.23
Area of Cube is: 627.917358

Explanation:

In the above program, we imported the "java.util.Scanner" package to read input from the user. And, created a public class Main. It contain two static methods calcuateAreaOfCube() and main().

The calcuateAreaOfCube() method is used to calculate the area of the Cube based on the given base and altitude.

The main() method is an entry point for the program. Here, we read basealtitude from the user using Scanner class. Then we calculated the area of Cube using the calcuateAreaOfCube() method and printed the result.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to find the Surface Area and volume o... >>
<< Java program to calculate the area of Parallelogra...