【发布时间】:2018-08-02 21:03:47
【问题描述】:
我需要第一个半径,但它无法识别,我该怎么做?顺便说一句,必须有两种方法,第二种方法必须使用第一种方法的半径。
public static double areaCircle(double rad) {
Scanner input = new Scanner(System.in);
System.out.print("Enter radius : ");
rad = input.nextDouble();
double circ = Math.PI*Math.pow(rad, 2);
return circ;
}
public static double volumeCylinder (double h) {
Scanner input = new Scanner(System.in);
System.out.print("Enter height : ");
h = input.nextDouble();
double cyl = Math.PI*Math.pow(rad, 2)*h;
}
【问题讨论】:
-
这听起来像是您误解了您的要求。
-
从函数中取出扫描器并将它们分配给变量。然后将变量传递给函数。在第二个函数中使用第一个函数的返回值。
-
为什么你有 rad/h 作为方法参数,还把 rad/h 作为输入!做两个之一!