沉吟丹青 2019-10-11 06:01 采纳率: 70%
浏览 205
已采纳

求助: volume cannot be solved as a variable 怎么解决?

让call一个method来计算圆锥体积
可是在printf的时候显示volume cannot be resovled to a variable
怎么修改呢?

package volume;

import java.util.Scanner;

public class VolumeofCone {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.printf("Enter the radius of the cone:\n");
double radius = input.nextDouble();
System.out.printf("Enter the height of the cone:");
double height = input.nextDouble();
System.out.printf("The volume of cone with radius %.4f and height %.4f is:%.4f \n", radius, height, volume);
double volume = getVolume(radius, height);

}

public static double getVolume(double radius, double height) {
    double volume = Math.PI * height * Math.pow(radius, 2) / 3;
    {
        return volume;

    }

}

}

  • 写回答

1条回答 默认 最新

  • 毕小宝 博客专家认证 2019-10-11 08:53
    关注

    把报错打印的那行放在 double volume 定义前面,变量必须先定义后使用。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services