注意空参构造方法传值方式
掌握知识点
- static关键字
- 空参构造方法传值方式
public class RingArea {
static final double PI = Math.PI;
double bigR;
double smallR;
public RingArea(){
this.smallR = 10.0;
this.bigR = 32.0;
}
public static double C(double bigR,double smallR){
double c = 2 * PI * (bigR + smallR);
return c;
}
public static double S(double bigR,double smallR){
double s = PI * (bigR * bigR - smallR * smallR);
return s;
}
public static void main(String[] args) {
RingArea ringArea = new RingArea();
double C = ringArea.C(ringArea.bigR, ringArea.smallR);
double S = ringArea.S(ringArea.bigR, ringArea.smallR);
System.out.print("该圆环的周长为" + String.format("%.2f",C) + ",面积为" + String.format("%.2f",S));
}
}