标签:package get util 编写 main ati 方法 私有 radius
package Circle;
import java.util.Scanner;
public class Circle {
private double Radius;
public double getRadius()
{
return Radius;
}
public void setRadius(double r)
{
this.Radius=r;
}
public Circle()//无参构造方法
{
this.Radius=0;//初始化为0
System.out.println("圆");
}
public Circle(double r)//带参构造方法
{
this.Radius=r;
}
public double getRadius()
{
return Radius;
}
public double getArea()//求圆的面积
{
double r=this.Radius;
return r*r*3.14;
}
public double getPerimeter()//求圆的周长
{
return this.Radius*3.14*2;
}
public void show()
{
Scanner cin=new Scanner(System.in);
System.out.println("请输入半径:");
this.setRadius(cin.nextInt());
System.out.println("半径=;"+this.getRadius());
System.out.println("周长;"+this.getPerimeter());
System.out.println("面积="+this.getArea());
}
public static void main(String args[])
{
Circle c=new Circle();
c.show();
}
}
标签:package get util 编写 main ati 方法 私有 radius
原文地址:https://www.cnblogs.com/gt33/p/8934082.html