• 对象数组


    对象数组

    .代码如下:

    package Day05; public class TestCircle1 {
    public static void main(String[] args) {
    // Circle c1 = new Circle(1.0);
    // Circle c2 = new Circle(2.0);
    //
    // c1.setRadius(10.0);
    // System.out.println(c1.getRadius());
    // System.out.println(Circle.getName()); // Circle c3 = new Circle(1.0);
    // printAreas(c3, 5); Circle[] cArray1 = createCircleArray();
    printCircleArray(cArray1);
    } private static void printCircleArray(Circle[] cArray) {
    for (int i = 0; i < cArray.length; i++) {
    System.out.println(cArray[i].getRadius() + " " + cArray[i].getArea());
    }

    double sum = 0.0;
    for (int i = 0; i < cArray.length; i++) {
    sum += cArray[i].getArea();
    }
    System.out.println(sum); } private static Circle[] createCircleArray() {
    Circle[] cArrayReturn = new Circle[5];
    for (int i = 0; i < cArrayReturn.length; i++) {
    cArrayReturn[i] = new Circle(Math.random() * 100);
    }
    return cArrayReturn;
    } private static void printAreas(Circle circle, int times) {
    for (int i = 0; i < times; i++) {
    System.out.println("The circle's area is: " + circle.getArea());
    circle.setRadius(circle.getRadius() + 1);
    } }
    }

    希望有帮助,我也是为了复习

    只相信苦尽甘来
  • 相关阅读:
    定位的原理
    UE4 开发三维GIS 一 场景光影
    UE4 开发三维GIS
    hive
    atlas
    开源AI药物发现TorchDrug安装测试的那些坑
    使用Docker快速搭建zabbix 5
    Docker简易部署
    简单的批量telnet 测试
    ASP.NET Core 中间件
  • 原文地址:https://www.cnblogs.com/F001li/p/7055749.html
Copyright © 2020-2023  润新知