JAVA作业——创建一个点类,创建一个圆类
发布网友
发布时间:2022-04-22 06:36
我来回答
共1个回答
热心网友
时间:2023-06-28 04:48
代码如下:
import java.util.Scanner;
class Circle {
private double radius;
public Circle(double radius) {
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double getArea() {
return Math.PI * radius * radius;
}
public double getPerimeter() {
return 2 * Math.PI * radius;
}
}
public class App {
public static void main(String[] argv) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入圆半径:");
double r = scanner.nextDouble();
Circle c = new Circle(r);
System.out.println("面积:" + c.getArea() + ",周长:" + c.getPerimeter());
}
}
运行结果: