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; } Circle c = new Circle(); Scanner scanner = new Scanner(System.in); System.out.print("请输入半径:"); double r = scanner.nextDouble(); c.setR(r); System.out.println("圆的面积(使用成员变量r):" + c.area()); 将以上代码中的main 方法定义为: public static void main(String[] args)
时间: 2023-06-26 08:09:20 浏览: 159
java代码-import java.util.Scanner;
5星 · 资源好评率100%
public static void main(String[] args) {
Circle c = new Circle();
Scanner scanner = new Scanner(System.in);
System.out.print("请输入半径:");
double r = scanner.nextDouble();
c.r = r;
System.out.println("圆的面积(使用成员变量r):" + c.area());
}
阅读全文