zoukankan      html  css  js  c++  java
  • 扩容数组

    package chapter7;
    //数组扩容

    public class TestArray {
    public static void main(String[] args) {

    // 创建数组
    int[] a = { 1, 4, 8, 6, 9 };
    // 扩容数组
    int[] b = new int[a.length];
    // 复制旧数组到新数组
    for (int i = 0; i < a.length; i++) {
    // a数组复制给b数组
    b[i] = a[i];

    }

    // a = b;//多余
    // 调用方法
    print(a);
    }

    // 遍历数组,定义一个形参作为局部变量
    public static void print(int[] array) {
    for (int i = 0; i < array.length; i++) {
    System.out.println(array[i]);
    }
    }
    }

  • 相关阅读:
    【NOI2015】荷马史诗
    Codeforces Round #415 (Div. 2)
    Codeforces Round #408 (Div. 2)
    bzoj3230
    poj1743
    poj1226
    bzoj1295
    bzoj1294
    bzoj1296
    bzoj1239
  • 原文地址:https://www.cnblogs.com/Koma-vv/p/9542047.html
Copyright © 2011-2022 走看看