java编程,定义类Circle,用成员变量r和常量PI求圆的面积,可以包括多种
发布网友
发布时间:2022-05-04 22:35
我来回答
共1个回答
热心网友
时间:2023-10-08 23:10
import java.util.Scanner;
public class Circle {
private static double π=3.14;
private static double s;
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
Circle circle=new Circle();
while(true){
double r=scanner.nextDouble();
s=circle.sCircle(r);
System.out.println("圆面积:"+s);
}
}
public static double sCircle(double r){
return π*r*r;
}
}
结果:
1
圆面积:3.14
2
圆面积:12.56
3
圆面积:28.259999999999998