Java计算环形面积代码,java计算环形面积代码怎么用
编写一个圆环类Ring的Java程序。 将参数传递给构造方法,计算圆环面积 area,在控制台输出。
public class Ring {
成都创新互联从2013年成立,是专业互联网技术服务公司,拥有项目成都网站设计、网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元八宿做网站,已为上家服务,为八宿各地企业和个人服务,联系电话:028-86922220
double innerRadius;
double outerRadius;
String color;
public Ring(double innerRadius,double outerRadius){
this.innerRadius=innerRadius;
this.outerRadius=outerRadius;
}
double area(){
return Math.PI*(Math.pow(outerRadius, 2)-Math.pow(innerRadius, 2));
}
public static void main(String args){
Ring r=new Ring(5,4);
System.out.println(r.area());
}
}
java 编写一个环形类 求环的面积
public class Ring
{
private double innerR;
private double outR;
public void setDate(double outR)
{
this.outR = outR;
}
public double getArea()
{
return Math.PI*outR*outR;
}
public static void main(String[] args)
{
Ring ring1 = new Ring();
ring1.setDate(2);
Ring ring2 = new Ring();
ring2.setDate(4);
System.out.println("第一个环面积为:" + ring1.getArea());
System.out.println("第二个环面积为:" + ring2.getArea());
}
}
java程序编程题
public class Ring {
private double outerRadius;
private double innerRadius;
private String color;
public Ring() {
}
public Ring(double outerRadius, double innerRadius, String color) {
this.outerRadius = outerRadius;
this.innerRadius = innerRadius;
this.color = color;
}
public double getOuterRadius() {
return outerRadius;
}
public void setOuterRadius(double outerRadius) {
this.outerRadius = outerRadius;
}
public double getInnerRadius() {
return innerRadius;
}
public void setInnerRadius(double innerRadius) {
this.innerRadius = innerRadius;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public double getArea(){
//计算环形面积
double outer = Math.PI * Math.pow(outerRadius, 2);
double inner = Math.PI * Math.pow(innerRadius, 2);
return outer - inner;
}
}
分享题目:Java计算环形面积代码,java计算环形面积代码怎么用
文章来源:http://scyanting.com/article/heghdc.html