java,定义一个圆类,再调用这个圆类输出半径,面积,周长
时间: 2023-05-23 16:07:20 浏览: 114
A:
```java
public class Circle {
private double radius;
private final double PI = 3.14;
public Circle(double radius) {
this.radius = radius;
}
public double getRadius() {
return radius;
}
public double getArea() {
return PI * radius * radius;
}
public double getPerimeter() {
return 2 * PI * radius;
}
public static void main(String[] args) {
Circle circle = new Circle(5);
System.out.println("半径为:" + circle.getRadius());
System.out.println("面积为:" + circle.getArea());
System.out.println("周长为:" + circle.getPerimeter());
}
}
```
输出结果为:
```
半径为:5.0
面积为:78.5
周长为:31.400000000000002
```
阅读全文