This is the Java Program to Find the Surface Area and Volume of a Cone.

Given the dimensions of a cone, find out its surface area and volume.

The surface area and volume of a cone can be calculated using the formulas:

**Surface Area = (PI * radius * slant height) + (PI * radius ^{2}).
Volume = PI * radius^{2} * height/3.
**

Here is the source code of the Java Program to Find the Surface Area and Volume of a Cone. The program is successfully compiled and tested using IDE IntelliJ Idea in Windows 7. The program output is also shown below.

`//Java Program to Find the Surface Area and Volume of a Cone`

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class Cone {

`// Function to calculate and print the surface area and volume of a cone`

public static void main(String[] args) {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

double radius,height;

System.out.println("Enter the radius and

height of the right circular cone");

try{

radius=Double.parseDouble(br.readLine());

height=Double.parseDouble(br.readLine());

}catch (Exception e){

System.out.println("An error occurred");

return;

`}`

if(radius<=0 || height<=0){

System.out.println("Wrong Input");

return;

`}`

double slantheight = Math.sqrt(Math.pow(radius,2) + Math.pow(height,2));

System.out.println("Volume = " + (Math.PI*Math.pow(radius,2)*height/3));

System.out.println("Surface area = " + ((Math.PI*radius*slantheight)

+ (Math.PI*radius*radius)));

`}`

`}`

1. In function main(), first, the radius and the height of the cone are taken as input.

2. The condition if(radius<=0 || height<=0) checks if the input is valid or not.

3. The print statement displays the surface area and volume of the cone.

**Time Complexity: O(1)**

Case 1 (Simple Test Case): Enter the radius and height of the right circular cone 3.42 12 Volume = 146.98129725379061 Surface area = 170.81027853689216

**Sanfoundry Global Education & Learning Series – Java Programs.**

**Related Posts:**

- Practice Information Technology MCQs
- Apply for Computer Science Internship
- Check Java Books
- Practice BCA MCQs
- Apply for Java Internship