用Java写一个求圆锥表面积和体积的程序
时间: 2024-05-30 14:15:47 浏览: 17
public class Cone {
private double radius;
private double height;
public Cone(double radius, double height) {
this.radius = radius;
this.height = height;
}
public double getSurfaceArea() {
double slantHeight = Math.sqrt((radius * radius) + (height * height));
double baseArea = Math.PI * (radius * radius);
double lateralArea = Math.PI * radius * slantHeight;
return baseArea + lateralArea;
}
public double getVolume() {
return (1.0 / 3.0) * Math.PI * (radius * radius) * height;
}
public static void main(String[] args) {
Cone cone = new Cone(5, 10);
System.out.println("Surface Area: " + cone.getSurfaceArea());
System.out.println("Volume: " + cone.getVolume());
}
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)