对象数组

对象数组

.代码如下:

package Day05; public class TestCircle1 {
public static void main(String[] args) {
// Circle c1 = new Circle(1.0);
// Circle c2 = new Circle(2.0);
//
// c1.setRadius(10.0);
// System.out.println(c1.getRadius());
// System.out.println(Circle.getName()); // Circle c3 = new Circle(1.0);
// printAreas(c3, 5); Circle[] cArray1 = createCircleArray();
printCircleArray(cArray1);
} private static void printCircleArray(Circle[] cArray) {
for (int i = 0; i < cArray.length; i++) {
System.out.println(cArray[i].getRadius() + "\t" + cArray[i].getArea());
}

double sum = 0.0;
for (int i = 0; i < cArray.length; i++) {
sum += cArray[i].getArea();
}
System.out.println(sum); } private static Circle[] createCircleArray() {
Circle[] cArrayReturn = new Circle[5];
for (int i = 0; i < cArrayReturn.length; i++) {
cArrayReturn[i] = new Circle(Math.random() * 100);
}
return cArrayReturn;
} private static void printAreas(Circle circle, int times) {
for (int i = 0; i < times; i++) {
System.out.println("The circle's area is: " + circle.getArea());
circle.setRadius(circle.getRadius() + 1);
} }
}

希望有帮助,我也是为了复习

posted @ 2017-06-20 18:45  辰峰  阅读(207)  评论(0编辑  收藏  举报