由于你的 PI 定义成了常量,所以必须把 PI 换成 “(sphere.PI)”

解决方案 »

  1.   

    .\sphere.java:16: cannot resolve sym
    symbol  : variable radius
    location: class sphere
      return sphere.PI*radius*x*y*z;
                       ^
    .\sphere.java:16: cannot resolve sym
    symbol  : variable x
    location: class sphere
      return sphere.PI*radius*x*y*z;
                             
    .\sphere.java:16: cannot 
    symbol  : variable y     
    location: class sphere
      return sphere.PI*radius*x*y*z;
                                ^
    .\sphere.java:16: cannot resolve sym
    symbol  : variable z
    location: class sphere
      return sphere.PI*radius*x*y*z;
                                  ^还是不行啊,继续请教了
      

  2.   

    class sphere{
      static final double PI=3.1415926;
      static int count=0;
      double xcenter;
      double ycenter;
      double zcenter;
      double radiu; ----> double radius;
      sphere(double radius,double x,double y,double z){
      radius=radiu; ----> this.radius = radius;
      xcenter=x;
      ycenter=y;
      zcenter=z;  
      ++count;
      }
      double vol(){
      return PI*radius*x*y*z;
      }
    public static void main(String[] args){
       sphere nn=new sphere(10,20,1.3,5);
       System.out.println(nn.vol());
    }
     }
      

  3.   

    还有,把x,y,z分别换成xcenter,ycenter,zcenter
      

  4.   

    你在非static函数里调用了static变量,将double vol()改成static double vol()就可以了
      

  5.   

    各位老大,你们说的方法怎么没有一个可以啊?
    By:风之子,你的“你在非static函数里调用了static变量,将double vol()改成static double vol()就可以了”这个说法不能成立哦,拜托各位老大,请继续,出错的代码我也贴出来了,出错就在这4个变量上,拜托拜托
      

  6.   

    错误很多:
    class sphere{
      static final double PI=3.1415926;
      static int count=0;
      double xcenter;
      double ycenter;
      double zcenter;
      double radiu;
      sphere(double radius,double x,double y,double z){
      radius=radiu; //radiu是成员变量,没有赋值则java默认初值0.0,这是你想要的吗?
      xcenter=x;
      ycenter=y;
      zcenter=z;  
      ++count;
      }
      double vol(){
      return PI*radius*x*y*z; //错误1:x,y,z是sphere类构造方法的参数,能在这里调用吗?
      }
    public static void main(String[] args){
       sphere nn=new sphere(10,20,1.3,5);
       System.out.println(nn.vol());
    }
     }
      

  7.   

    看这样行不!!
    class sphere{
      static final double PI=3.1415926;
      static int count=0;
      double xcenter;
      double ycenter;
      double zcenter;
      double radiu;
      sphere(double radius,double x,double y,double z){
      radiu=radius; 
      xcenter=x;
      ycenter=y;
      zcenter=z;  
      ++count;
      }
      double vol(){
      return PI*radiu*xcenter*ycenter*zcenter;
      }
    public static void main(String[] args){
       sphere nn=new sphere(10,20,1.3,5);
       System.out.println(nn.vol());
    }
     }
      

  8.   

    class sphere{
      static final double PI=3.1415926;
      static int count=0;
      double xcenter;
      double ycenter;
      double zcenter;
      double radiu;
      sphere(double radius,double x,double y,double z){
      radius=radiu; 
      xcenter=x;
      ycenter=y;
      zcenter=z;  
      ++count;
      }
      double vol(){
      return PI*radius*x*y*z; 
      }
    public static void main(String[] args){
       sphere nn=new sphere(10,20,1.3,5);
       System.out.println(nn.vol());
    }
     }
      

  9.   

    各位大哥,我是新手,这个程序是我按书上的步骤写的,他的程序可以运行阿?《java2编程指南 sdk 1.4》的154页的例子,我狂晕,你们觉得他的步骤很乱吗?FT
      

  10.   

    对不起,应该是159页,写得非常清楚,就是讲构造器的,上面的
    sphere(double radius,double x,double y,double z){
      radius=radiu; 
      xcenter=x;
      ycenter=y;
      zcenter=z;  
      ++count;
      }
      double vol(){
      return PI*radius*x*y*z; 
    我自己也试出来了,但是我就是没明白为什么我按书上的做就是不行?我是新手,让大家见笑了
      

  11.   

    啊呀!!!!!!!!!!!!!!!!!!!!!!搞定,非常感谢singlehuang