共回答了18个问题采纳率:94.4%
public class Circle{
private double radius;
public Circle(double r){
this.radius = r;
}
public static void main(String args[]){
Circle[] ary = new Circle[5];
ary[0] = new Circle(1);
ary[1] = new Circle(2);
ary[2] = new Circle(3);
ary[3] = new Circle(4);
ary[4] = new Circle(5);
double area = 0;
for(int i = 0;i < ary.length; i++){
area = area + ary[i].area();
}
System.out.println("Total area is: " + area);
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double area(){
return Math.PI * radius * radius;
}
public double circle(){
return 2 * Math.PI * radius;
}
}
-------------
Total area is: 172.7875959474386
1年前
1