import java.util.Scanner; public class Circle { private double r; public Circle() { } public Circle(double r) { this.r = r; } public double area() { return Math.PI * r * r; }} 将代码中的main 方法定义为: public static void main(String[] args)
时间: 2023-06-26 21:09:34 浏览: 217
java代码-import java.util.Scanner;
import java.util.Scanner;
public class Circle {
private double r;
public Circle() {
}
public Circle(double r) {
this.r = r;
}
public double area() {
return Math.PI * r * r;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入圆的半径:");
double r = scanner.nextDouble();
Circle circle = new Circle(r);
System.out.println("圆的面积为:" + circle.area());
}
}
阅读全文