我必须找到每个矩形面积的平均总和。我可以找到每个矩形的面积,我应该将每个面积存储到一个数组中并通过它找到平均值吗?还是那不可能?
ArrayList<Rectangle> list = new ArrayList<Rectangle>();
list.add(new Rectangle(0, 0, 25, 50));
list.add(new Rectangle(0, 0, 10, 30));
list.add(new Rectangle(0, 0, 100, 40));
list.add(new Rectangle(0, 0, 40, 45 ));
list.add(new Rectangle(0, 0, 13, 13));
double aAvg = 0.0;
for (int i = 0; i < list.size(); i++ ) {
double h = list.get(i).getHeight();
double w = list.get(i).getWidth();
double area = h * w;
System.out.println(area);
}