```java public class Volume { // 计算长方体体积 public double calVolume(double length, double width, double height) { return length * width * height; } // 计算球体体积 public double calVolume(double radius) { return 4.0 / 3 * Math.PI * Math.pow(radius, 3); } // 计算圆柱体体积 public double calVolume(double radius, double height) { return Math.PI * Math.pow(radius, 2) * height; } public static void main(String[] args) { Volume volume = new Volume(); // 计算长方体体积 double length = 32.5; double width = 23.2; double height = 14; double cuboidVolume = volume.calVolume(length, width, height); System.out.println("长方体体积: " + cuboidVolume); // 计算球体体积 double radius = 12; double sphereVolume = volume.calVolume(radius); System.out.println("球体体积: " + sphereVolume); // 计算圆柱体体积 radius = 5; height = 20; double cylinderVolume = volume.calVolume(radius, height); System.out.println("圆柱体体积: " + cylinderVolume); } } ``` 额外注意点: 1. 确保计算体积的公式准确无误。 2. 注意数据类型的精度,避免计算结果出现较大误差。 3. 检查输出的体积结果是否符合预期。 [2024-11-27 11:02:36 | AI写代码神器 | 362点数解答]