这是我必须完成的任务:
定义一个具有双重参数baseLength、baseWidth和pyramidHeight的pyramidVolume方法,该方法返回的体积是具有矩形底面的棱锥体的两倍。
下面是我的代码:
import java.util.Scanner;
public class CalcPyramidVolume {
public static void pyramidVolume (double baseLength, double baseWidth, double pyramidHeight) {
  baseLength = 1.0;
  baseWidth = 1.0;
  pyramidHeight = 1.0;
  double pyramidVolume = ((baseLength * baseWidth) * pyramidHeight) / 3;
}   
public static void main (String [] args) {
  System.out.println("Volume for 1.0, 1.0, 1.0 is: " + pyramidVolume(1.0, 1.0, 1.0));
  return;
}
}我只能编辑我创建pyramidVolume方法调用的那段代码。我收到一个错误,说这里不允许'void‘类型,并且它指向我不能编辑的system.out行。我很困惑为什么它会在那一行上给我一个错误。
发布于 2016-03-28 11:38:22
pyramidVolume返回类型为void。将返回类型改为double,如下所示:
public static double pyramidVolume (double baseLength, double baseWidth, double pyramidHeight) {
  double pyramidVolume = ((baseLength * baseWidth) * pyramidHeight) / 3;
  return pyramidVolume;
}  https://stackoverflow.com/questions/36255557
复制相似问题