It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center
                            
                        
                    
                
                7年前关闭。
            
        

运行程序时,出现以下错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at CylinderTest.main(Cylinder.java:42)


我敢肯定有一个简单的解决方案,但是我是一个没有经验的程序员,对我来说似乎应该可以。

程序说明:编写一个名为CylinderTest.java的类并声明
三个Cylinder对象的数组,用于调用您在其中声明的方法
Cylinder类。确保从中调用所有类方法
主要()。让main()显示volume()返回的值并验证
手工计算得出的返回值(纸张/铅笔)。提示用户
输入每个圆柱对象的半径和高度的值
在数组中。

public class Cylinder
{
  private double radius;
  private double height;
  public Cylinder(double radius, double height)
  {
      this.radius = radius;
      this.height = height;
  }
  public double getRadius()
  {
      return radius;
  }
  public double getHeight()
  {
      return height;
  }
  public double volume()
  {
      return radius*radius*height*3.1416;
  }


}

public class CylinderTest
{

public static void main(String[] args)
{

    Cylinder[] myCylinder = new Cylinder[3];
    myCylinder [0] = new Cylinder (2,7);
    myCylinder [1] = new Cylinder (9,3);
    myCylinder [2] = new Cylinder (12,4);
    for (Cylinder c: myCylinder)
    {
        System.out.println("*******");
        System.out.println("Radius: " + c.getRadius());
        System.out.println("Height: " + c.getHeight());
        System.out.println("Volume: " + c.volume());
        System.out.println("*******");
    }
}
}

最佳答案

线程“主”中的异常java.lang.Error:未解决的编译
  问题:
  
  在CylinderTest.main(Cylinder.java:42)


由于Cylinder文件中第42行存在错误,因此无法编译您的类Cylinder.java

关于java - 持续收到我程序的错误代码,有人可以看看吗? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13370909/

10-08 23:00