1 public class Homework13{ 2 //编写一个mian方法 3 public static void main(String[] args){ 4 Circle c = new Circle(); 5 PassObject po = new PassObject(); 6 po.printAreas(c,5); 7 8 } 9 } 10 11 12 class Circle{ 13 double radius;//半径 14 public Circle(){//无参构造器 15 16 } 17 public Circle(double radius){ 18 this.radius = radius; 19 } 20 public double findArea(){//返回面积 21 return Math.PI * radius * radius; 22 } 23 //添加方法setRadius,修改对象的半径值 24 public void setRadius(double radius){ 25 this.radius = radius; 26 } 27 } 28 class PassObject{ 29 public void printAreas(Circle c, int times){ 30 System.out.println("radius\t area"); 31 for(int i = 1;i <= times;i++){ 32 c.setRadius(i); 33 System.out.println((double)i + "\t" + c.findArea()); 34 } 35 } 36 }
标签:printAreas,定义,PassObject,double,radius,半径,Circle,public From: https://www.cnblogs.com/wzyxslx/p/18378699