第1个回答 2019-10-31
public class Cylinder {
private double radius;
private double height;
private double pi = Math.PI;
public Cylinder(double radius, double height) {
this.radius = radius;
this.height = height;
}
private double area() {
return this.pi * this.radius * this.radius;
}
private double volume() {
return this.area() * this.height;
}
public static void main(String[] args) {
Cylinder cylinder = new Cylinder(2.5, 5);
System.out.println("底面积:" + cylinder.area());
System.out.println("体积:" + cylinder.volume());
}
}