Java program to calculate the surface area and volume of Cone

Given the values of height and radius, we have to calculate the surface area and volume of Cone.
Submitted by Nidhi, on February 28, 2022

Problem Solution:

In this program, we will read height, radius from the user and calculate the surface area, volume, of the cone.

Program/Source Code:

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

// Java program to calculate the surface area 
// and volume of Cone

import java.util.Scanner;

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

    double height = 0;
    double radius = 0;

    double volume = 0;
    double area = 0;

    System.out.printf("Enter the height: ");
    height = SC.nextDouble();

    System.out.printf("Enter the radius: ");
    radius = SC.nextDouble();

    volume = (1.0F / 3) * (3.14F) * radius * radius * height;
    area = (3.14F) * radius * (radius + Math.sqrt(radius * radius + height * height));

    System.out.printf("Volume of Cone 	    : %f\n", volume);
    System.out.printf("Surface area of Cone: %f\n", area);
  }
}

Output:

Enter the height: 2.34
Enter the radius: 4.67
Volume of Cone      : 53.414362
Surface area of Cone: 145.075675

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 contains a static method main().

The main() method is an entry point for the program. Here, we read height, radius from the user using the Scanner class. Then we calculated the volume and surface area of Cone and printed the result.

Java Basic Programs »



Related Programs




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.