代码如下:
public class Test {
public static void main(String[] args) {
double[] radiusArray = new double[10]; //半径数组
double[] areaArray = new double[10]; //面积数组
for (int i = 0; i < radiusArray.length; i++) {
double radius = Math.random()*50+10; //半径
radiusArray[i] = radius;
double perimeter = 2*Math.PI*radius; //周长
double area = Math.PI*Math.pow(radius,2); //面积
System.out.printf("圆%d:半径=%f,周长=%f,面积=%f \n",i+1,radius,perimeter,area);
areaArray[i] = area; //把面积存起来,之后算体积要用
}
double[] heightArray = new double[10];
for (int i = 0; i < radiusArray.length; i++) {
double radius = radiusArray[i]; //获取之前产生的半径
double height = Math.random()*50+10; //高度
heightArray[i] = height;
double zhuArea = areaArray[i]*height; //圆柱体积:底面积*高
double zhuiArea = zhuArea/3; //圆锥体积:圆柱体积的1/3
System.out.printf("第%d个:半径=%f,高=%f,圆柱体积=%f,圆锥体积=%f \n",i+1,radius,height,zhuArea,zhuiArea);
}
}
}