62,614
社区成员
发帖
与我相关
我的任务
分享
public class Spere
{
double r,s,l;
public Spere(double R)
{
r=R;
}
public double countlength()
{
l=Math.PI*2*r;
return l;
}
public double countarea()
{
s=Math.PI*r*r;
return s;
}
public double setR(double h)
{
r=h;
return r;
}
public static void main(String[]args) //这里写错 ,java的main应该是static的
{
Spere s1=new Spere(3.0);
System.out.println("半径为3.0的圆周长为:"+s1.countlength());//由于countlength未定义为static,所以需要加上s1
System.out.println("半径为3.0的圆面积为:"+s1.countarea());
s1.setR(5.0);//由于setR未定义为static,所以需要加上s1
System.out.println("半径为5.0的圆周长为:"+s1.countlength());
System.out.println("半径为5.0的圆面积为:"+s1.countarea());
}
}