image.png

    1. package com.atguigu.exercise;
    2. public class PassObject {
    3. public static void main(String[] args) {
    4. Object t = new Object();
    5. Circle c = new Circle();
    6. t.printAreas(c, 5);
    7. System.out.println("now radius is " + c.radius);
    8. }
    9. }
    10. class Object{
    11. public void printAreas(Circle c, int time) {
    12. System.out.println("Radius \t \t Area");
    13. // 设置圆的半径
    14. for (int i = 1; i <= time; i++) {
    15. c.radius = i;
    16. System.out.println(c.radius + "\t\t" + c.findArea());
    17. }
    18. c.radius = time + 1;
    19. }
    20. }
    21. class Circle {
    22. double radius;// 半径
    23. // 求圆的面积
    24. public double findArea() {
    25. return Math.PI * radius * radius;
    26. }
    27. }