代码如下:
package cao.com.duixiang;
public class TestCCircle {
public static void main(String[] args) {
PassObjectt op = new PassObjectt();
CircleC cc = new CircleC();
op.printArea(cc, 5);
System.out.println("the now radious is "+cc.getRadious());
}
}
class CircleC{
double radious;
public double findArea(){
return Math.PI*(radious*radious);
}
public double getRadious() {
return radious;
}
public void setRadious(double radious) {
this.radious = radious;
}
}
class PassObjectt{
public void printArea(CircleC c,int times){
System.out.println("times"+"\t\t"+"Areas");
int temp = 0;
for(int i =1;i<=times;i++,temp=i){
c.setRadious(i);
System.out.println(c.getRadious()+"\t\t"+c.findArea());
}
c.setRadious(temp);
}
}
时间: 2024-10-20 10:20:25